Best practices for ensuring the data in dynamically created views is up to date

Kyle's Avatar


12 Jul, 2013 04:44 PM

Morning all!

So I'm running into what seems to be an age-old questions in the Robotlegs world (at least by the amount of threads out there around this topic, it seems that it's been a very commonly asked question): What is the "best" way to make sure that the data in a dynamically created view is up-to-date?

Ex: On application startup, some external data is loaded and stored in a data model. The model dispatches an event out to the framework to let everyone know that its' data has been updated. Some time later a view (let's say a modal window of some sort) is created and attached to the display list. This window uses the data that is stored in the model to populate itself, and has a listener for the models update event, but since it is created after the event is dispatched, it won't receive the update.

Potential solutions that I have found:
1) Inject the model into the mediator for the view and grab the data when the mediator is initialized, then use the even listeners to listen for any further updates to the model. (This seems to break best-practices, as it tightly couples the view to the model).

2) Setup a request/response event system where the view dispatches a request for some data and the model responds with a response containing the data requested. (This sounds like a good way to handle things, though it does seem to introduce quite a bit of overhead in terms of the events, commands, etc. that would be required to implement it. Perhaps there is a way to simplify this process that I haven't thought of yet).

3) Use the relaxedEventMap. (This seems like a very straightforward solution, but requires the extra overhead of mapping all the events to the relaxedEventMap. I am also curious if there would be any concerns about the performance of this extension. The specific case I'm thinking of is a model that dispatches an update notification each time a new object is added (say 20 times over), would the relaxedEventMap then queue each of these individual events and blast the view with them when it is created?).

So I guess what I'm wondering is personal thoughts on the best solution to this issue, and (fingers crossed) if there is possibly a new/better way to handle this in RL2?

Thanks as always!


  1. Support Staff 1 Posted by Shaun Smith on 12 Jul, 2013 04:52 PM

    Shaun Smith's Avatar

    I'd just go with option 1.

    This seems to break best-practices, as it tightly couples the view to the model

    It tightly couples the mediator (not the view) to the model. Mediators are, by their nature, coupled to the application (and hence model) layer.

  2. 2 Posted by Kyle on 12 Jul, 2013 05:07 PM

    Kyle's Avatar

    Valid point man! And thanks for the correction on the mediator being coupled not the view (waiting for the coffee to do its' thing still) ;-)

  3. Ondina D.F. closed this discussion on 30 Aug, 2013 07:55 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