How do I preload data from a async service

corey's Avatar


13 Jan, 2012 07:35 AM

I would like to preload some data from an external source that is required before any of the views can be created and start requesting data of the their own.

Do I create a manual injection within the startup function?

Is there another function I can override within the context class?

  1. 1 Posted by Nangra on 13 Jan, 2012 09:27 AM

    Nangra's Avatar

    Maby execute command that will preload data from Context startup method?

  2. Support Staff 2 Posted by creynders on 13 Jan, 2012 12:49 PM

    creynders's Avatar

    Here's an example of bootstrapping an application with several async service calls before anything else happens:

  3. Support Staff 3 Posted by Ondina D.F. on 13 Jan, 2012 01:02 PM

    Ondina D.F.'s Avatar

    @creynders Ha! I was just about to recommend your example :)

  4. 4 Posted by corey on 14 Jan, 2012 12:39 AM

    corey's Avatar

    What if I am not using signals though? Would this approach still work?

  5. Support Staff 5 Posted by creynders on 14 Jan, 2012 08:38 AM

    creynders's Avatar

    Yes. It doesn't make a difference at all. You do need the macrobot extension though. Obviously there are other ways as well, by using a state machine for instance:

  6. 6 Posted by corey on 14 Jan, 2012 09:41 PM

    corey's Avatar

    Ok, I was able to get something working based off the demo-bootstrap above without using signals.

    Here is some code snippets for other people to reference. If I am not following best practices please point them out.

    Essentially what I did was listen for the STARTUP Event that I manually dispatched and then robotlegs called the Command that was mapped.
    Inside this command I dispatch another command that calls an async service to retrieve the data. Once the data is retrieved I then map all the mediators using the detain/release methods.

    More about the STARTUP EVENTS can be found in the following thread

    override public function startup():void
                // This allows me to preload some data from an esync service
                commandMap.mapEvent(ContextEvent.STARTUP, ApplicationStartupCommand);
                this.dispatchEvent(new ContextEvent(ContextEvent.STARTUP));
                // Startup complete

    Snippet form Command

    public class ApplicationStartupCommand extends Command
            public function ApplicationStartupCommand()
            override public function execute():void{
                new BootstrapCommands(commandMap);
                new BootstrapModels(injector);
                this.eventDispatcher.addEventListener(ProfilesEvent.PROFILESRESULT, onSettingsHandler);
                dispatch(new SettingsServiceEvent(SettingsServiceEvent.READ_REQUEST, "profiles"));
            private function onSettingsHandler(event:ProfilesEvent):void{
                //settings have been read from the disk
                new BootstrapViewMediators(mediatorMap);
  7. corey closed this discussion on 14 Feb, 2012 06:46 AM.

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