@nichoth/bus

0.0.2 • Public • Published

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')
})

Readme

Keywords

Package Sidebar

Install

npm i @nichoth/bus

Weekly Downloads

0

Version

0.0.2

License

ISC

Last publish

Collaborators

  • nichoth