Context startup events

shawn's Avatar

shawn

11 Jan, 2010 04:52 PM

I'm evaluating Robotlegs ( I really like the look of it ) and I see 2 ways of proceeding in the contexts startup method. One example calls super.startup() which in turn dispatches ContextEvent.STARTUP_COMPLETE. The other example does not call the super method and instead dispatches ContextEvent.STARTUP.

Which one is correct? I'm assuming one of those events must be required for the rest of the robots to begin doing something.

Thanks!

  1. 1 Posted by levi.strope on 11 Jan, 2010 05:36 PM

    levi.strope's Avatar

    It is my understanding that you don't need to dispatch either of these events.

    I have noticed that If I try to listen for these events that they never get caught - I've found that if I want to do something on STARTUP_COMPLETE I had to dispatch this myself on the last line of Context.startup();

  2. Support Staff 2 Posted by Joel Hooks on 11 Jan, 2010 05:39 PM

    Joel Hooks's Avatar

    both do the same thing and neither are "correct" I personally dispatch it explicitly in my concrete startup just for clarity in my own apps.

  3. 3 Posted by shawn on 11 Jan, 2010 07:53 PM

    shawn's Avatar

    Ok, it seems most examples use the explicit dispatch, so I guess I'll go that route. Thanks for the quick responses! I guess we are probably stuck with both since I'm sure many people went different routes.

  4. 4 Posted by jadd on 11 Jan, 2010 08:08 PM

    jadd's Avatar

    hello. another stupid question. Why the explicit dispach works for me and the other super.startup does not.?

  5. 5 Posted by shawn on 11 Jan, 2010 08:20 PM

    shawn's Avatar

    Are you explicitly dispatching the same event that super.startup uses?

  6. Support Staff 6 Posted by Shaun Smith on 11 Jan, 2010 08:25 PM

    Shaun Smith's Avatar

    super.startup() will fire a ContextEvent.STARTUP_COMPLETE event. When developing modules it is often useful to know (from the outside) when a context has been fully initialized.

    By overriding startup() you, the app developer, are intercepting this flow and it is up to you to dispatch this event manually. You might not do this directly from the startup() method - perhaps some asynchronous call needs to be made first - you might dispatch it from a command, or you might not even dispatch it at all.

    STARTUP and STARTUP_COMPLETE are simply provided for app development convenience, they don't play any part in Robotlegs itself.

    For large applications/contexts, a suggested workflow is as follows:

    1. startup() maps some bootstrapping Commands to the STARTUP event
    2. startup() dispatches the STARTUP event
    3. The mapped commands run, in sequence, and
    4. The final command dispatches the STARTUP_COMPLETE event

    For smaller apps this is unnecessary as all the initialization happens in the startup() method, and we can consider the application "started" by the end of that method.

    Hope that helps!

  7. 7 Posted by shawn on 11 Jan, 2010 09:08 PM

    shawn's Avatar

    Yes it does. Thanks!

  8. Shaun Smith closed this discussion on 13 Feb, 2010 05:20 PM.

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

Keyboard shortcuts

Generic

? 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