Is there a way to do real-time data using Ember.js?
What I'm looking for is the ability to insert updated and new records (rather than deleting) into previously returned results.
So, let's say I have routers that look like this, which allows sorting and swap (aka skip):
App.Router.map(function() { this.resource('messages', { path: '/messages/skip/:skip/sort/:sort/direction/:direction' }); }); App.MessagesRoute = Ember.Route.extend({ model: function(params) { this.set('params', params); return this.query(); }, query: function() { var sort = {}; sort[this.get('params').sort] = parseInt(this.get('params').direction); return App.Message.find({}, { skip: this.get('params').skip, sort: sort }); }, setupController: function(controller, model) { var self = this; this._super(controller, model); Ember.Instrumentation.subscribe('onMessage', { before: function(name, timestamp, message) { self.controller.set('content', self.query()); }, after: function() {} }); }, });
This works great - it sorts and skips correctly in a static sense.
(NOTE: I am NOT using Ember Data - just a collection of Ember objects.)
However, the messages are received continuously, and I want the display of these messages to automatically request a new message when they arrive.
I have a websocket that tells me when this happens and it works correctly, and I use the Ember.Instrumentation infrastructure to route this event to close the setupController that I have. But when I do
this.controller.set('content', this.query());
In response to this event, to reload, the content disappears. What am I doing wrong?