Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Show Posts

* | |

  Show Posts
Pages: [1]
1  Announcements and General Discussion / Getting Started / Re: Question about startup on: August 01, 2008, 03:01:45
I find sometimes seeing several examples helps a concept become clearer.  I was stalled on a similar issue til I discovered the onRegister function.  I'll include an account here for reference.

Scenario:

In the constructor for myMediator I retrieve a proxy which handles a web service and then call a method named 'send' on the proxy.

Currently, since I don't have my web service set up yet I have hard coded some test data for the proxy to send as a notification body.  This notification is sent in the 'send' method.  When the web service is set up and working, the 'send' method on the proxy will add a listener to the web service and invoke it.  An 'onResult' handler in the proxy will then send the notification with the data as body.

Currently the code executes in this order:
  • view component fires creationComplete event
  • a mediator listening to this event registers a mediator for the new view component
  • in the new mediator's constructor the proxy is retrieved
  • the 'send' method is invoked
  • the 'send' method sends a 'dataReady' notification (with the test data)
  • the new mediator's constructor exits and it is registered with the view
  • as part of the registration with the view, the mediator is interrogated for it's notification interests, which happen to include the 'dataReady' notification (so that it can display said data)

You see my problem.  In the final version, the mediator will have finished being registered with the View and interrogated before the web service comes back, thus allowing the mediator to respond to the 'dataReady' notification.

Moving the call to the web service to the onReady function of my mediator means that the mediator has been interrogated and is ready to respond to the notification by the time the proxy returns data (be it hardcoded or from the actual service itself).  This seems to work just fine.

2  Announcements and General Discussion / Architecture / Appropriate use of MXML WebService on: July 02, 2008, 03:33:14
Does using PureMVC in a Flex app prevent the use of data services that are mxml based?

I was going about implementing a web service in one of my proxies when I discovered that there is an AS3 version and an mxml version.  They seem similar with the exception that the mxml version includes a property called showBusyCursor (which I would like to use so that the user knows that the UI is waiting on the remote data to load).  The AS3 version doesn't have this ability. 

Would it be horrible to put an mxml WebService (non-visual) component in my display hierarchy and cache a reference to it in my proxy?  It sounds not-right somehow (coupling model and view).  There may be a way to send a notification as I invoke the WebService that the view will respond to which will set the cursor to busy and then send another notification onResult to change the cursor back, but that also seems a bit clunky.  I guess it's really a reflection of flex allowing you to define display objects as well as non-visual data-layer and business-layer objects (Xml, Bindings, WebService for example) in mxml.  Is there a way to use these mxml classes that seem to be made for things that fall into the model and controller areas in a way that adheres to best practices?
3  Announcements and General Discussion / Getting Started / Re: Better startup idiom on: June 20, 2008, 03:31:45
Never you mind.  I found the problem.

Further into things, in a mediator's constructor I was sending the view component to the superclass constructor by using the getter name rather than the name that came in as an argument to the mediator class constructor, thus:

public class MyMediator extends Mediator implements IMediator {
...
public function MyMediator( viewComponent:MyComponent ) {
super ( NAME , myComponent );
}
private function get myComponent():MyComponent {
return viewComponent as MyComponent;
}
...
}

where my call to the superclass constructor should've been:

super ( NAME, viewComponent );

The wack thing is that it didn't throw a compiler error or a runtime error.  Apparently AS3 doesn't appreciate it if you use class getters in the superclass constructor.

Reminds me of the Dispair, Inc. poster that says something like "the purpose of your life may be to serve as a warning to others".  So, yes - don't try that in your own code.
4  Announcements and General Discussion / Getting Started / Re: Better startup idiom on: June 20, 2008, 12:53:12
Having issues with the facade starting up.

In my ApplicationFacade concrete facade class I have a method called startup, thus:

public function startup ( app:MyApp ):void {
   sendNotification ( STARTUP, app );
}

where STARTUP is public static const STARTUP:String = "startup"; in said class, and MyApp is the name of my main application (the mxml file in my src directory marked as the startup app for the project whose main mxml component is Application).

I've included the PureMVC swc in my library build path (it's in Flex Builder 3/PureMVC_AS3_2_0_3/bin).

In MyApp.mxml I have an import for the ApplicationFacade and I getInstance() and then call ApplicationFacadeInstance.startup.  For some reason the facade doesn't initialize properly and then the app continues running like normal (the view loads and I can click the buttons, etc.).

In my Application component I call a method (called starting) of MyApp on the creationComplete event.  In starting() I have the ApplicationFacadeInstance.startup() followed immediately by testingBool = true; (which variable I inspect later in the code to ensure that this particular block gets executed).  The problem is that if I call the startup method, the line testingBool = true; never executes.  If I comment out the startup method call, then testingBool = true; does execute.

I'm guessing it's some little thing I've missed after staring at the code too long.  Anybody have any ideas?

It occurs to me that since the libs folder in my project appears empty even though I set the library build path in the project properties that maybe I just need to put the swc in my project's lib folder directly rather than including the path.  However, I'd like to use the same swc in multiple projects.  But I'll give it a try just to check and see if that's the issue.  I kind of don't think it is, since I don't get compiler errors when I have my import statements, or at runtime when I instantiate the concrete facade.
5  Announcements and General Discussion / Architecture / Re: Mediator <=> View Component Coupling on: June 20, 2008, 10:18:11
Good stuff and helpful.  Cliff, would you recommend having the mediator set the currentState property, or having named constants for states and a public function that accepts such a const and uses a switch statement to set the view?  About the only advantage in refactoring is if you change the state names I would think.
6  Announcements and General Discussion / Architecture / Re: ViewStacks, Mediators and Deferred Instantiation on: June 18, 2008, 02:36:32
Yes, the Take 1/Take 2 post was extremely helpful in explaining a few things for me.

Questions:

1. In the checkForMediator function I get a 'possibly undefined method' error on the retrieveMediator call.  The class I'm using it in is MyMediator extends mediator implements IMediator - just like in the example.  I noticed in a search of the forums for 'retrieveMediator' that someone had facade.retrieveMediator, and in the Framework Overview it shows a retrieveMediator method on Facade and View classes, but not the Mediator class.  Is there something different I should do to check for the existence of mediators for views that use deferred instantiation?

2. (this one's minor) I noticed you are using buttons to switch views in the ViewStack in the example and have the mediator code setting the public property currentViewSelector to which the ViewStack's selectedIndex is bound.  I decided to use a TabBar to switch the views in the ViewStack and have the parent component mediator's event handling code simply check for the view mediator and send a notification to the facade for further use.  I have the ViewStack set as the dataProvider for the TabBar and the mediator listens for the ViewStack's change event.  Does this sound right and is the order of events right, or am I violating any idioms or best practices?

Thanks much.
7  Announcements and General Discussion / Architecture / Re: Mediator Exists but View Component not instantiated on: May 29, 2008, 12:25:46
Good idea 'bout the wiki.

I set up a temp one (at least for the deferred instantiation topic) in the meantime while we anxiously await more documentation and courseware and stuff (I know Cliff's got a lot going on).

Here you go:  puremvc.jinglesthepirate.com

If it's slow loading I appologise.  My hosting usually is a tad faster.

The wiki's limited for now.  If we want, I could open it up to cover the full framework, but I'm not sure about having a 3rd party (me) host it.
8  Announcements and General Discussion / Architecture / Re: View composed of view on: May 22, 2008, 02:41:18
Question about Flex states:

When Flex changes states there is much adding and removing of children.  Depending on the complexity of the view components you may have as many or almost as many mediators as there are view components.

When the components are added and removed I'm sure that events are fired that can be listened to and that on these events the appropriate mediator(s) can instantiate and register (on add) or unregister and dispose of (on remove) mediators for these view components.

My question is (1) where and (2) when to add the event listeners? 

What about nested components?  Example: my application has a state that adds a custom component, which itself has multiple states and may itself contain custom components with their own states and nested components.  Depending on the complexity of the application, this nesting of stateful components may be arbitrarily deep.

Cliff, am I right in thinking that you are suggesting that the Application has a single Viewstack that fires a specific even any time any view component is added to it and that the ApplicationMediator can listen to this event and responds appropriately (either by setting up the corresponding mediator(s) or passing on that task and a reference to the newly added view component to a command)?  That would make sense, but my questions then would be what is the event name, how do I reference the view components as they are added, and if that reference is something like lastChildAdded will the framework have time to respond by executing the code to grab the reference before the next view component is added to the Viewstack (I'm assuming that event handler functions execute when a creationComplete or childAdded event or the like fires before the runtime continues on to add the next view component as the application or component changes view state).

Thanks for the great framework and being so helpful in the forums.
Pages: [1]