Closed barelyknown closed 9 years ago
I'm confused....why are you doing all this?
If you have dynamic channels/events you just make sure you've defined PUSHER_SUBSCRIPTIONS
before calling this._super()
. Thats it :)
init: function() {
var eventName = 'dynamic-event';
this.PUSHER_SUBSCRIPTIONS = ['foo-channel' : eventName]';
this._super();
}
Because I don't know the eventName
until after init
.
Gotcha, so what you use in that case, is just wire
.
Just a note, @mmun and I have been talking about moving the pusher functionality into a service so this API will change in the future.
You have access to the pusher service in your routes and controllers because of: https://github.com/jamiebikies/ember-pusher/blob/master/lib/ember-pusher/initializer.js#L29-L30
The API to wire is:
wire(target, channelName, events)
Where target is the object that will be #send
to, channelName
is a string, and events
is an array of strings.
events: ['foo-event', 'bar-event'],
init: function() {
this.set('channelName', "example-channel" + this.get('id'));
},
channelNameChanged: function() {
this.get('pusher').wire(this, this.get('channelName'), this.get('events'));
}.observes('channelName').on('init')
OK. That's pretty close to what I did - thanks for clarifying that I wasn't missing something.
No problem, I've updated the example above a bit! :metal:
I'm wiring up subscriptions on a
Controller
that does not have what it needs duringinit
to define the key for the channel. So, I added awireSubscriptions
function that is called by theRoute
once it has what it needs duringsetupController
.app/routes/organization/buyer/loads.js
app/controllers/organization/buyer/loads.js
Two questions:
wireSubscriptions
function be extracted frominit
in the library so that it can be called when necessary?