0.0.2 • Published 6 years ago

@nichoth/bus v0.0.2

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

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

6 years ago

0.0.0

6 years ago