Reputation: 139
I'm using backbone js with an xml api data feed. I have a top-level model for each page that receives the xml and converts it into json. I then have additional methods in the model that return specific parts of the json model to the specific views through a controller. This is all working as expected.
I would like to periodically (via setTimeout) update the top-level model and have it fire the change event and update the views. My question is where I should handle/initialize the firing of this periodic event to update the model since it's not really a user trigger event?
Upvotes: 0
Views: 1097
Reputation: 16361
I'd give my model a startUpdate()
method, an endUpdate()
method, and an internal onTimerUpdate()
method that did a fetch. You can then call, on the model, the startUpdate()
and let it run as needed, pausing it when it would be inconvenient for a server-side update to run (say, in the middle of a customer manipulation of the data), and restarting it after a client-side change had successfully completed a write to the server.
Better yet, you could make it a mixin and use it with a number of different models.
Upvotes: 1