qipp-services-pubsub
v1.0.1
Published
Pubsub service for Angular application.
Downloads
5
Readme
qipp-services-pubsub
General
The pubsub service provides event methods per topic to extend objects, therefore allowing subscription/unsubscription/emission.
Install
npm i qipp-services-pubsub
Angular usage
First, use the pubsub() method to extend a given object:
function inc() {
obj.prop++
}
var obj = pubsub({prop: 1})
obj.$on('anEvent', inc)
obj.$emit('anEvent') // obj {prop: 2}
obj.$off('anEvent')
obj.$emit('anEvent') // No change: obj {prop: 2}
Note that the unsubscription could be done for a specific callback:
obj.$off('anEvent')
Moreover, the subscription/unsubscription could be done on multiple topics simultaneously:
obj.$on('anEvent' 'anotherEvent')
obj.$off('anEvent' 'anotherEvent')
Tools
Linting with StandardJS
Please refer to the JavaScript Standard Style for general rules.
npm run lint
Unit testing with Karma
npm test
Requirements
Angular
- angular 1.4.3
Licence
Released under the MIT license by qipp.