Simple to use implementation of event bus.
As for now needs ES2015.
npm install chab --save
<script type="text/javascript" src="chab.js"></script>
import { CreateChab } from 'chab'
const chab = CreateChab()
const sub = chab.subscribe('topicName', data => {
console.log(`Welcome ${data.name}!`)
})
chab.publish('topicName', { name: 'User' })
sub.unsubscribe()
chab.CreateChab()
Subscribes on given topic. Callback is called with two arguments:
- data which is passed by
publish
function - unsubscribe function, which when called will unsubscribe
Publishes message on given topic. If no subscriber will be found at publish time message gets stored and dispatched when somebody finally subscribes.