qipp-services-pubsub

Pubsub service for Angular application.

Usage no npm install needed!

<script type="module">
  import qippServicesPubsub from 'https://cdn.skypack.dev/qipp-services-pubsub';
</script>

README

qipp-services-pubsub Build Status npm version

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

Licence

Released under the MIT license by qipp.