From 14c8e0dddb3214d9a59230cd36ec0e1d0fba3256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mu=C3=B1oz?= Date: Thu, 1 May 2014 14:58:39 -0400 Subject: [PATCH] Register as "pusher:main" --- lib/ember-pusher/bindings.js | 12 ++++-------- lib/ember-pusher/client_events.js | 4 +--- lib/ember-pusher/controller.js | 3 ++- lib/ember-pusher/initializer.js | 5 +++-- test/lib/controller_test.js | 2 +- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/ember-pusher/bindings.js b/lib/ember-pusher/bindings.js index 9429e43..b95ed06 100644 --- a/lib/ember-pusher/bindings.js +++ b/lib/ember-pusher/bindings.js @@ -3,27 +3,23 @@ var global = (typeof window !== 'undefined') ? window : {}, var Bindings = Ember.Mixin.create({ - needs: 'pusher', - init: function() { - var pusherController, target; + var target; this._super(); if(!this.PUSHER_SUBSCRIPTIONS) { return; } - pusherController = this.get('controllers.pusher'); target = this; Object.keys(target.PUSHER_SUBSCRIPTIONS).forEach(function (channelName) { var events = target.PUSHER_SUBSCRIPTIONS[channelName]; - pusherController.wire(target, channelName, events); + target.pusher.wire(target, channelName, events); }); }, willDestroy: function() { - var pusherController, target; + var target; if(!this.PUSHER_SUBSCRIPTIONS) { return; } - pusherController = this.get('controllers.pusher'); target = this; Object.keys(target.PUSHER_SUBSCRIPTIONS).forEach(function (channelName) { - pusherController.unwire(target, channelName); + target.pusher.unwire(target, channelName); }); this._super(); }, diff --git a/lib/ember-pusher/client_events.js b/lib/ember-pusher/client_events.js index 519d7f2..fc519c3 100644 --- a/lib/ember-pusher/client_events.js +++ b/lib/ember-pusher/client_events.js @@ -3,12 +3,10 @@ var global = (typeof window !== 'undefined') ? window : {}, var ClientEvents = Ember.Mixin.create({ - needs: 'pusher', - // Fire an event programmatically. All Events must unfortunately use // the client- format for client events (a pusher restriction). pusherTrigger: function(channelName, eventName, data) { - var channel = this.get('controllers.pusher').channelFor(channelName); + var channel = this.pusher.channelFor(channelName); channel.trigger(eventName, data); } diff --git a/lib/ember-pusher/controller.js b/lib/ember-pusher/controller.js index 71b58a1..6698c71 100644 --- a/lib/ember-pusher/controller.js +++ b/lib/ember-pusher/controller.js @@ -105,7 +105,7 @@ var Controller = Ember.Controller.extend({ bindings[channelName].channel = pusher.subscribe(channelName); // Spit out a bunch of logging if asked - if(this.namespace.PUSHER_OPTS.logAllEvents) { + if(this.namespace && this.namespace.PUSHER_OPTS.logAllEvents) { bindings[channelName].channel.bind_all(function(eventName, data) { console.log( "Pusher event received on " + channelName + ":", @@ -140,6 +140,7 @@ var Controller = Ember.Controller.extend({ }, channelFor: function(channelName) { + // debugger; return this.get('bindings')[channelName].channel; }, diff --git a/lib/ember-pusher/initializer.js b/lib/ember-pusher/initializer.js index 11792f6..fb9fa02 100644 --- a/lib/ember-pusher/initializer.js +++ b/lib/ember-pusher/initializer.js @@ -15,10 +15,10 @@ function initialize() { initialize: function(container, application) { var pusherController, options, pusher, dict; - dict = 'controller:pusher'; + dict = 'pusher:main'; container.register(dict, Controller); - pusherController = container.lookup('controller:pusher'); + pusherController = container.lookup(dict); options = application.PUSHER_OPTS; Ember.assert("You need to provide PUSHER_OPTS on your application", options); @@ -26,6 +26,7 @@ function initialize() { pusher = new Pusher(options.key, options.connection); pusherController.didCreatePusher(pusher); + console.log('totes injected'); application.inject('controller', 'pusher', dict); application.inject('route', 'pusher', dict); } diff --git a/test/lib/controller_test.js b/test/lib/controller_test.js index ffd753c..7d3ca49 100644 --- a/test/lib/controller_test.js +++ b/test/lib/controller_test.js @@ -23,7 +23,7 @@ App = Ember.Application.create({ describe("Controller", function() { before(function(){ - pusherController = App.__container__.lookup('controller:pusher'); + pusherController = App.__container__.lookup('pusher:main'); pusherController.get('connection').connection.socket_id = '1234'; channelName = 'craycraychannel'; bindings = pusherController.get('bindings');