Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
public function MyProxy() { //argument-less constructor super(NAME, null);}
public final class MyProxy extends Proxy { ...}
if (!facade.hasProxy(MyProxy.NAME)) { facade.registerProxy(new MyProxy(MyProxy.NAME)); //data is set later}var myProxy:IProxy = facade.retrieveProxy(MyProxy.NAME);
if (!facade.hasProxy(MyProxy.NAME)) { facade.registerProxy(new MyProxy());}var myProxy:IProxy = facade.retrieveProxy(MyProxy.NAME);
var myProxy:IProxy = MyProxy.getInstance();
this class can't even be extended so why not just make it final?
I have a situation (which I think is common) where my proxy basically defines its own name by default and (since it gets its data remotely) also doesn't need the data parameter in its constructor.
public function MyProxy() { // still an argument-less constructor super(NAME, new Array()); // make sure that methods that manipulate the collection won't bomb}
facade.registerProxy(new MyProxy(MyProxy.NAME)); //data is set later
I just don't like singleton pattern in AS 3.0 because Adobe doesn't encourage it and by extension the language doesn't properly support it.
public function EmployeeDetailProxy( employeeVO:EmployeeVO ) { super(employeeVO.id, employeeVO);}
// MainScreenView.as[Bindable] public var currentProject:ProjectSummaryVO = new ProjectSummaryVO;// happens when user selects a project item on the data gridpublic function selectProjectHandler(event:ListEvent):void { // populate currentProject from selected item currentProject = event.itemRenderer.data as ProjectSummaryVO; // go get this project's details this.dispatchEvent(new ProjectEvent(ProjectEvent.GET_PROJECT_DETAIL, currentProject));}
// MainScreen Mediatoroverride public function onRegister():void { appProxy = facade.retrieveProxy(ApplicationProxy.NAME) as ApplicationProxy; loginProxy = facade.retrieveProxy(LoginProxy.NAME) as LoginProxy; projectProxy = facade.retrieveProxy(ProjectProxy.NAME) as ProjectProxy; // listen for main screen events mainScreen.addEventListener(LogoutEvent.LOGOUT, tryLogout); mainScreen.addEventListener(ProjectEvent.GET_PROJECT_DETAIL, getProjectDetail);}// create a unique proxy for this project's details public function getProjectDetail(event:ProjectEvent):void { facade.registerProxy(new ProjectDetailsProxy(event.project);}
// ProjectDetailsProxy //// remote object instance referencesprivate var project:ProjectDetailVO = new ProjectDetailVO(); // constructor takes project public function ProjectDetailsProxy(currentProject:ProjectSummaryVO) { project.projectID = currentProject.projectID; super(currentProject.projectID.toString(), project);} // configure the proxy when registeredpublic override function onRegister():void { projectService = new RemoteObject("ProjectService"); projectService.source = "TSProjectRunwayServiceLibrary.com.tspr.business.ProjectService"; projectService.getOperation("getProjectDetails").addEventListener(ResultEvent.RESULT, projectDetailsLoaded); projectService.getOperation("getProjectDetails").addEventListener(FaultEvent.FAULT, projectDetailsFailed); // immediately get the project details getProjectDetails(this.projectVO.projectID);}
Am I overwriting an existing ProjectDetailsProxy when I click one project, click another project and then click back on the previous one?
// create a unique proxy for this project's details public function getProjectDetail(event:ProjectEvent):void { if ( ! facade.hasProxy( ProjectSummaryVO( event.project ).projectID ) { facade.registerProxy( new ProjectDetailsProxy( event.project ) ); }}
// configure the proxy when registeredpublic override function onRegister():void { projectService = new RemoteObject("ProjectService"); projectService.source = "TSProjectRunwayServiceLibrary.com.tspr.business.ProjectService"; projectService.getOperation("getProjectDetails").addEventListener(ResultEvent.RESULT, projectDetailsLoaded); projectService.getOperation("getProjectDetails").addEventListener(FaultEvent.FAULT, projectDetailsFailed);}public var loaded:Boolean=false; // set true by projectDetailsLoaded public function getProjectDetails( id:string ):void{ if (loaded) { //previously fetched // send same note that projectDetailsLoaded sends with cached details sendNotification(PROJECT_DETAILS_LOADED, data); } else { // fetch now projectService.getProjectDetails(id); }}
// create a unique proxy for this project's details public function getProjectDetail(event:ProjectEvent):void { var projectID:String = ProjectSummaryVO( event.project ).projectID var detailsProxy:ProjectDetailsProxy = facade.retrieveProxy( projectID ); if ( detailsProxy == null ) detailsProxy = new ProjectDetailsProxy( event.project ); facade.registerProxy( detailsProxy ); } detailsProxy.getProjectDetails(projectID);}
Cairngorm has singletons, and Adobe certainly advocates its use. There is a lot of FUD (fear, uncertainy and doubt) about singletons to be sure. The 'singletons are useful / evil' horse has been beaten to a pulp here and elsewhere on the interwebs, so I won't get into it other than to say that used improperly, they can certainly do more harm than good, but that they do have a place. Just not as Proxies.If you implement that Proxy as a Singleton, there's nothing to prevent you from just snagging the instance in your view component as a quick and easy way of getting at the data. That might seem expedient, but it ties the view component to the framework, an anti-pattern.