> Small publish & subscribe class
npm install @crabas0npm/nihil-fuga-aut> Small publish & subscribe class
#### npm
``sh`
npm i --save @crabas0npm/nihil-fuga-aut
`js`
import PubSub from '@crabas0npm/nihil-fuga-aut'
const pubsub = new PubSub()
`js
import PubSub from '@crabas0npm/nihil-fuga-aut'
const pubsub = new PubSub()
pubsub.subscribe('event', (value) => {
console.log(value)
})
pubsub.publish('event', 'hello')
// always runs handler
// (can use to overide littlePubsub.verbose setting without changing the behavior of the rest)
pubsub.publishVerbose('event', 'hello')
pubsub.unsubscribe('event', (value) => {
console.log(value)
})
pubsub.hasSubscribers('event')
await pubsub.once('event')
`
verbose: when false only fires after value change
`js`
pubsub = new PubSub({
verbose: false // default: true
})
#### subscribe
name: name of the channel to subscribe tohandler: methodcontext: context
`js`
pubsub.subscribe('event-name', (data) => {
console.log(data)
})
#### unsubscribe
name: name of the channel to unsubscribehandler: methodcontext: context
`js`
pubsub.unsubscribe('event-name', (data) => {
console.log(data)
})
#### publish
name: name of the channel to publish tohandler: methodverbose: boolean
`js`
pubsub.publish('event-name', 'data')
#### publish
name: name of the channel to publish tohandler: method
`js`
pubsub.publishVerbose('event-name', 'data')
#### once
name: name of the channel to publish to
`js`
await pubsub.once('event-name')
#### hasSubscribers
name: name of the channel to publish to
`js``
pubsub.hasSubscribers('event-name')