Application entry point

Alex's Avatar

Alex

08 Jan, 2011 01:15 PM

Hi!
I was looked into several RL examples (FlickrGallery, CafeTownsend) and found that application's entry point is in a main view's mediator (the service's load method call etc). Is it a best practice? I think View must not to deal with application logic.. What do you think about it?

  1. 2 Posted by Paul Robertson on 08 Jan, 2011 03:41 PM

    Paul Robertson's Avatar

    I've been surprised to see that pattern a couple of times recently too.

    Personally I like to use a different pattern. I see the context's
    startup method as the "app entry point" for wiring purposes (which is
    the same in any RL app I suppose). For any "on startup" actions such as
    checking for updates, loading the initial data, etc. I have those
    actions in one or more commands that are mapped to the
    ContextEvent.STARTUP_COMPLETE event. You can trigger that event by
    calling super.startup() in the context's startup() method. You can also
    just manually dispatch the event at the end of your startup() method
    (which is actually what I've always done because I only recently learned
    that super.startup() dispatches that event).

    Paul

    P.S. on a related note, I see that the fact that those events are
    dispatched isn't documented. I guess I may be adding something to my
    fork of Robotlegs today =)

  2. 3 Posted by Alex on 08 Jan, 2011 03:54 PM

    Alex's Avatar

    ContextEvent.STARTUP_COMPLETE event is quite the thing, thank you Paul!

  3. 4 Posted by Stray on 08 Jan, 2011 04:24 PM

    Stray's Avatar

    +1 for that method. I use bootstrap commands wired to the STARTUP_COMPLETE event to kick things off.

  4. 5 Posted by Abel de Beer on 09 Jan, 2011 11:25 AM

    Abel de Beer's Avatar

    Yup, I also prefer the ContextEvent.STARTUP_COMPLETE method.

  5. 6 Posted by Weyert on 09 Jan, 2011 01:50 PM

    Weyert's Avatar

    Yes, I am also using ContextEvent.STARTUP_COMPLETE too. I am not sure yet what the best way is to deal with a bunch files that needed to be loaded at start-up.

  6. 7 Posted by Abel de Beer on 09 Jan, 2011 02:47 PM

    Abel de Beer's Avatar

    @Weyert:

    Right now I'm working on a relatively big project where a lot of mappings need to be made at startup. I use the same strategy as Stray (I think), which is something like this:

    In my Context::startup() method:

    commandMap.mapEvent(ContextEvent.STARTUP_COMPLETE, ConfigModelAndServiceCommand); commandMap.mapEvent(ContextEvent.STARTUP_COMPLETE, ConfigControllerCommand); commandMap.mapEvent(ContextEvent.STARTUP_COMPLETE, ConfigViewCommand); commandMap.mapEvent(ContextEvent.STARTUP_COMPLETE, StartupCommand); super.startup();

    Each of these 'Config[...]Command' classes contains the actual mappings for Model and Service, Controller and View respectively. In my StartupCommand I call the actual first method to initialize the application, in my case calling a 'load' method on an XMLService.

    I think Stray uses the word "Bootstrap" instead of "Config", which is probably a better description, but somehow I don't like the word. Bootstrap... Ugh. ;)

  7. 8 Posted by Weyert on 09 Jan, 2011 07:08 PM

    Weyert's Avatar

    @Abel: Yes, I am also having something like you but I would like to load XML files before kicking starting StartupCommand. Currently, I am using the code below to solve this problem but I am not happy with it:

            commandMap.mapEvent( ApplicationEvent.LOADING,             BootstrapControllers, ApplicationEvent, true );
            commandMap.mapEvent( ApplicationEvent.LOADING,             BootstrapServices, ApplicationEvent, true );
            commandMap.mapEvent( StatisticsServiceEvent.CREATED,       BootstrapModels, StatisticsServiceEvent, true );
            commandMap.mapEvent( StatisticsServiceEvent.CREATED,       BootstrapViews, StatisticsServiceEvent, true );
            commandMap.mapEvent( StatisticsServiceEvent.CREATED,       BootstrapApplyConfiguration, StatisticsServiceEvent, true );
    
            commandMap.mapEvent( StatisticsServiceEvent.CREATED,       BootstrapLoadMessages, StatisticsServiceEvent, true );
    

    BootstrapMessagesLoaded, MessagesModelEvent, true );

            commandMap.mapEvent( StatisticsServiceEvent.CREATED,       LoadStatisticsCommand, StatisticsServiceEvent, true );
            commandMap.mapEvent( StatisticsServiceEvent.LOADED,        BootstrapStatisticsLoaded, StatisticsServiceEvent, true );
            commandMap.mapEvent( StatisticsServiceEvent.LOADED,        StartViewCommand, StatisticsServiceEvent, true );
            dispatch( new ApplicationEvent( ApplicationEvent.LOADING ) );
    

    As you can see it will continue with bootstrapping after StatisticsServiceEvent.CREATED has been dispatched which creates and options a specific SQLite database. All the event mappings exists only once also I am having a StatisticsEvent.LOADED which means a record has been read from the database.

  8. Stray closed this discussion on 13 Feb, 2011 03:51 PM.

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