Mediator event listener not listening until after startup command has finished

Josh Grauer's Avatar

Josh Grauer

30 Sep, 2010 09:44 PM

I've created a StartupCommand that is called after I dispatch ContextEvent.STARTUP within my context. The StartupCommand maps models, views, and some application level events. Once it is done, I dispatch ContextEvent.STARTUP_COMPLETE which starts the process of retrieving some pictures from flickr and loading them up in my model. Once the photos have finished loading, I dispatch another event which I want my mediator to pick up so that a slide show can start playing.

This worked great when calling flickr's web service to retrieve the photos, but when I switched my service over to a static XML representation I found that the mediator was never getting the "all photos loaded" event. After throwing some debug breakpoints around I learned that the static XML was getting loaded into the model before the mediator had even mapped the event.

I was hoping that there was some type of event that the framework fired off once all the mediator's onRegister methods had done there thing so that I could safely start loading up some data, but I didn't see anything in the API. The only solution I can see is having the mediator's onRegister method dispatch an event letting the framework know that it's done setting up its listeners, but I can see where that could get really cumbersome if you have several mediators all waiting for each other to finish so that the data can be loaded.

Any suggestions on how I should be approaching this?

  1. 1 Posted by creynders on 01 Oct, 2010 08:28 AM

    creynders's Avatar

    I'd let the mediator check whether the model already contains the required data, and in case it does, fire up the slide show.

  2. 2 Posted by Josh Grauer on 01 Oct, 2010 04:38 PM

    Josh Grauer's Avatar

    That's definitely a better idea than having the mediator dispatch an event.

    The way this app works is it loads several photo sets and when all sets have loaded it dispatches an event. If I were to have the mediator look at the model to see if everything is loaded I'd have that logic in more than one place, which I'm not too hot on.

    I guess I could make a method in the model that checks if all photo sets are loaded and have both the mediator and model use that one method, that wouldn't be too bad. Thanks for the idea, I think that is the best approach at this point.

  3. Stray closed this discussion on 10 Feb, 2011 05:52 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac