1

I have a standard issue route like:

App.MessagesRoute = Ember.Route.extend({

    model: function() {
        return App.Message.find();
    }

});

Which works great for the existing set of messages that i get from a REST endpoint. But I also get new messages via a websocket. How in the RC2 routing architecture (and non-Ember Data store) how do I plumb new message like these into Ember cleanly?

outside2344
  • 2,075
  • 2
  • 29
  • 52

1 Answers1

0

I solved this using the Ember.Instrumentation framework element that's talked about in How to fire an event to Ember from another framework.

Here's my complete code:

...
// this is fired from my websocket message reception code.

Ember.Instrumentation.instrument('onMessage', message);
...

App.MessagesRoute = Ember.Route.extend({

    setupController: function(controller, model) {
        Ember.Instrumentation.subscribe('onMessage', {
            before: function(name, timestamp, message) {
                controller.send('onMessage', message);
            },
            after: function() {}
        });
    },

    model: function() {
        return App.Message.find();
    }

});


App.MessagesController = Ember.ArrayController.extend({
    onMessage: function(message) {
        this.unshiftObject(message);
    }
});
Community
  • 1
  • 1
outside2344
  • 2,075
  • 2
  • 29
  • 52