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 / Architecture / Event listener placement on: May 28, 2008, 10:13:49
I have some questions of my own, but I think I can answer your question about obtaining the component reference. I recommend you create a custom event to hold a reference to the newly created component. Perhaps have the component pass in a reference to itself on it's creationComplete event.

:
creationComplete="dispatchEvent(new ComponentLoadedEvent(ComponentLoadedEvent.COMPLETE, this));"
ComponentLoadedEvent is your custom event and the second parameter is a reference to itself (the view component).

My question is the same as yours, where should the event listeners be added and handled? I think the most obvious answer is to have each components "parent" handle the load event and register the mediator, but this will not work. Let me try to explain. Let's assume component A is some child component buried deep inside the view hierachy (many layers below the application), and component B is a child component of A. If we register the event listener for component B in component A's mediator and if A's mediator was registered after A's creationComplete event by some parent mediator, then component B's component loaded handler won't be called. This is because A's mediator constructor will be called after A's creationComplete and creationComplete means that all of A's sub-components are "complete" as well. Therefore B's loaded handler never get's called because B's component loaded event will have already been dispatched by the time the listener is registered!!

Does this mean all the component loaded events should bubble up and that we should handle all of them in the ApplicationMediator; whether it handles it internally or uses a command? Or maybe the listeners need to be registered in the "initialize" event instead of the creationComplete event? If we use the initialize event to register mediators then we come back to the same problem where we can't use the mediator's constructor properly.

We need to depend on loading events for all components and can't assume that we only have to use it for viewstacks and similar components. Flex is very unpredictable and occasionally just decides to get out of sync with respect to loading components.  :D

Thanks Cliff for all your great help!! There are many forums out there with great support, but this is the first I've seen where the actual project creator is really dedicated to the community. It's a blessing to all of us that are just starting to learn the flex architecture, even for those of us who have many years of experience in architecting large webapps in other languages.  ;)
Pages: [1]