A simple pubsub mechanism for Ember.js
Questions? Ping me @gavinjoyce
This is an Ember CLI addon, to install:
npm install ember-pubsub --save-dev
// app/controllers/example.js
import Ember.Controller.extend({
pubsub: Ember.inject.service(),
setup: Ember.on('init', function() {
var pubsub = this.get('pubsub');
pubsub.subscribe('sayHello', this, function(name) {
console.log('hello ' + name);
});
}),
actions: {
hello: function() {
this.get('pubsub').publish('sayHello', 'Alex'); // => hello Alex
},
noMoreHellos: function() {
this.get('pubsub').unsubscribe('sayHello');
}
}
});
git clone
this repositorynpm install
bower install
ember server
- Visit your app at http://localhost:4200.
npm run test
MIT