tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/788-how-do-i-preload-data-from-a-async-serviceRobotlegs: Discussion 2018-10-18T16:35:35Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/128774272012-01-13T09:27:57Z2012-01-13T09:27:58ZHow do I preload data from a async service <div><p>Maby execute command that will preload data from Context startup
method?</p></div>Nangratag:robotlegs.tenderapp.com,2009-10-18:Comment/128774272012-01-13T12:49:10Z2012-01-13T12:49:10ZHow do I preload data from a async service <div><p>Here's an example of bootstrapping an application with several
async service calls before anything else happens:<br>
<a href=
"https://github.com/creynders/robotlegs-demo-bootstrap">https://github.com/creynders/robotlegs-demo-bootstrap</a></p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/128774272012-01-13T13:02:54Z2012-01-13T13:02:54ZHow do I preload data from a async service <div><p>@creynders Ha! I was just about to recommend your example :)</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/128774272012-01-14T00:39:46Z2012-01-14T01:31:08ZHow do I preload data from a async service <div><p>What if I am not using signals though? Would this approach still
work?</p></div>coreytag:robotlegs.tenderapp.com,2009-10-18:Comment/128774272012-01-14T08:38:47Z2012-01-14T08:38:47ZHow do I preload data from a async service <div><p>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:<br>
<a href=
"https://github.com/joelhooks/robotlegs-utilities-StateMachine">https://github.com/joelhooks/robotlegs-utilities-StateMachine</a></p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/128774272012-01-14T21:41:23Z2012-01-14T21:41:23ZHow do I preload data from a async service <div><p>Ok, I was able to get something working based off the
demo-bootstrap above without using signals.</p>
<p>Here is some code snippets for other people to reference. If I
am not following best practices please point them out.</p>
<p>Essentially what I did was listen for the STARTUP Event that I
manually dispatched and then robotlegs called the Command that was
mapped.<br>
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.</p>
<p>More about the STARTUP EVENTS can be found in the <a href=
"http://knowledge.robotlegs.org/discussions/questions/422-contexteventstartup-contexteventstartup_complete">
following thread</a></p>
<pre>
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
super.startup();
}
</pre>
<p>Snippet form Command</p>
<pre>
public class ApplicationStartupCommand extends Command
{
public function ApplicationStartupCommand()
{
super();
}
override public function execute():void{
new BootstrapCommands(commandMap);
new BootstrapModels(injector);
this.eventDispatcher.addEventListener(ProfilesEvent.PROFILESRESULT, onSettingsHandler);
dispatch(new SettingsServiceEvent(SettingsServiceEvent.READ_REQUEST, "profiles"));
commandMap.detain(this);
}
private function onSettingsHandler(event:ProfilesEvent):void{
//settings have been read from the disk
new BootstrapViewMediators(mediatorMap);
commandMap.release(this);
}
}
</pre></div>corey