Existing Data Event Flow ... Call for opinions/best practices
I currently have my Model(s) dispatching applicable ITEMS_UPDATED events when the entire list of data changes. This works especially well when batch-loading data from services as the service does the parsing and just calls a set on the model. Go decoupling!
However, I'm curious as to the best practice the next time a View requests the same data that has been "cached" in the model. I have come up with two options ... neither of which is without drawbacks.
1) The Mediator is Model Aware.
Mediator checks the model onRegister/CreationComplete and can
simply call the view setter if data already exists. If the data
doesn't exist, dispatch a data request event. Simple, effective,
coupled.
2) The Command does the "cache" checking.
In the command, call the service if the data doesn't yet exist. But
what if the data exists? Do people generally dispatch the "same"
ITEMS_UPDATED event from the command or do you call a helper method
to nudge the model into re-reporting. [Note: In this case I want
the benefit of local data storage so always calling the service
path is not desirable. I have a force flag on the event for
refreshes.]
This approach is decoupled, but now I have to manage event dispatching from two places. Even if I decide to just nudge the model into re-reporting the event, I still could have the wasted overhead of an extra event and maybe additional view processing if multiple views are currently presenting this data and need to respect the ITEMS_UPDATED event.
Interested in everyone's views on these two approaches and for any other suggesions.
Thanks in advance,
Justin
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by creynders on 02 Mar, 2012 12:44 PM
IMO, re-reporting is definitely not right, since the items have NOT been updated.
One of the simplest solutions is to use the relaxed eventmap utility:
https://github.com/Stray/robotlegs-utilities-RelaxedEventMap
if a listener subscribes to an event after-the-fact it will automatically be triggered.
Ondina D.F. closed this discussion on 30 Mar, 2012 09:01 AM.
Ondina D.F. re-opened this discussion on 26 Apr, 2012 07:53 AM
3 Posted by Justin on 26 Apr, 2012 04:35 PM
creynders,
Thanks for the feedback and apologies for not responding sooner. I was up against a deadline and the thread was closed when I returned to thank you.
I like the sound of the relaxed eventmap, but since I had a deadline, I ended up just injecting the model and conditionally requesting the data if it had not been previously loaded.
I'm ok with the coupling for now, but I would love it if something like the relaxed eventmap was stock in RL. This seems to be a very common need.
Thanks again,
Justin
Ondina D.F. closed this discussion on 21 Jun, 2012 08:08 AM.