4 ms·
I think that frameworks like Rails or Django are not built to solve this problem out-of-the-box. Thus if you're not careful enough you'll end up with some messy
by igorgue 15y ago
I think that frameworks like Rails or Django are not built to solve this problem out-of-the-box. Thus if you're not careful enough you'll end up with some messy ass JavaScript code (and I have seen it everywhere).
Lately though, I've started to build apps using Backbone (I guess you can use Knockout or Batman too) and Django (or Rails) just to build the API, and it's very simple to do this.
All you have to do is:
// Poll every 10 seconds to keep the channel model up-to-date.
setInterval(function() {
channel.fetch();
}, 10000);
At least in Backbone http://documentcloud.github.com/backbone/#Model-fetch http://documentcloud.github.com/backbone/#Model-fetch
- prateekdayal 15y agoThat's a great approach. I think one issue that can crop up if you do a fetch and reload the entire listing, some state like checked rows in the table etc can be lost. So you have to add some more logic to preserve it. I think that's why it's a good idea to start thinking about this right at the start of your app/page.
- igorgue 15y agoI think you can just bind the "add" event on the collection (I might be wrong) and fetch wont re-render (since you wont bind the "render all" function) the whole collection.