https://github.com/joelhooks/angular-browserify-event-dispatcher
https://github.com/joelhooks/angular-browserify-event-dispatcher
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/joelhooks/angular-browserify-event-dispatcher
- Owner: joelhooks
- Created: 2014-03-02T23:16:25.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-03-03T00:57:23.000Z (over 11 years ago)
- Last Synced: 2024-04-25T13:00:32.468Z (about 1 year ago)
- Size: 141 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Sometimes it's nice to use a global event bus in your applications. This dispatcher wraps a bit of the eventing functionality from $rootScope to create an event bus that other actors in your application can use.
## DispatchingController
The dispatching controller is a *mixin* for your controllers to enhance their behavior.
``` javascript
angular.module('my-module', [
require('angular-browserify-event-dispatcher').name
])
/**
* This is how you'd use the dispatcher
*/
.controller('myController', function ($scope, DispatchingController) {
var time = new Date();
// `this` scope can be an issue here. It might be
// required to assign `var myController = this`
// in some cases.
//
// this could be `angular.extend` vs the Object.mixin ;)
angular.extend(this, new DispatchingController($scope));
this.listen('hi', function (event, msg) {
console.log('event handled:', time, msg, event);
});
this.dispatch('hi', 'from controller')
})
.service('myService', function(dispatch) {
dispatch('hi', 'from service');
})
```