@nichoth/bus
v0.0.2
Published
An event bus where you can pass in a static list of event names
Downloads
2
Readme
bus
Pass in a list of event names when you create a bus, then throw an error if you subscribe to an event that's not in the list.
This inherits from nanobus, and has the same API, except for the constructor.
install
$ npm install @nichoth/bus
example
var test = require('tape')
var Bus = require('../')
var bus = Bus(['hello'])
test('bad event name', function (t) {
t.plan(1)
try {
bus.on('foo', () => console.log('foo'))
} catch (err) {
t.equal(err.message, 'Invalid event name foo')
}
})
test('good event name', function (t) {
t.plan(1)
bus.on('hello', function (data) {
t.equal(data, 'world', 'subscriptions work')
})
bus.emit('hello', 'world')
})
test('dont throw if given no event names', function (t) {
t.plan(1)
var bus = Bus()
bus.on('foo', function (data) {
t.equal(data, 'bar')
})
bus.emit('foo', 'bar')
})