How do I preload data from a async service
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?
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
1 Posted by Nangra on 13 Jan, 2012 09:27 AM
Maby execute command that will preload data from Context startup method?
Support Staff 2 Posted by creynders on 13 Jan, 2012 12:49 PM
Here's an example of bootstrapping an application with several async service calls before anything else happens:
https://github.com/creynders/robotlegs-demo-bootstrap
Support Staff 3 Posted by Ondina D.F. on 13 Jan, 2012 01:02 PM
@creynders Ha! I was just about to recommend your example :)
4 Posted by corey on 14 Jan, 2012 12:39 AM
What if I am not using signals though? Would this approach still work?
Support Staff 5 Posted by creynders on 14 Jan, 2012 08:38 AM
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:
https://github.com/joelhooks/robotlegs-utilities-StateMachine
6 Posted by corey on 14 Jan, 2012 09:41 PM
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
Snippet form Command
corey closed this discussion on 14 Feb, 2012 06:46 AM.