Skip to content
A simple node.js ESB implementation using EventEmitter.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
test
.eslintrc.json
.gitignore
.travis.yml
README.md
bus.js
gulpfile.js
package.json

README.md

NPM version Build Status Coverage Status

A simple node.js Enterprise Software Bus (ESB) implementation using EventEmitter.

See some examples

Installation

$ npm install eventemitter-bus --save

Development

$ npm install
$ npm test

API

// Default instance
let bus = require('eventemitter-bus');

// Or an instance managed by you
let bus = new require('eventemitter-bus').Bus();

bus.provide(name, obj, replace);

bus.provide('calculator', {
    sub: function(a, b) {
        bus.emit('calculator.sub', {
            a: a
            , b: b
            , result: a - b
        });
    }
})

bus.replace(name, obj)

bus.replace('calculator', {
    add: function(a, b) {
        bus.emit('calculator.add', {
            a: a
            , b: b
            , result: a + b
        })
    }
});

bus.on(event, fn)

bus.on('calculator.sub', (res) => {
    console.log('calculator.sub =>', res);
});

bus.run(name)

bus.run('calculator.sub', 10, 5);

bus.fn.run(name)

// alias to bus.run()
bus.fn.run('calculator.sub', 10, 5);

bus.fn.provide(name, fn, replace)

bus.fn.provide('calculator', function add(a, b) {
    bus.emit('calculator.add', {
        a: a
        , b: b
        , result: a + b
    });
});

bus.fn.replace(name, fn)

bus.fn.replace('calculator', function sub(a, b) {
    bus.emit('calculator.sub', {
        a: a
        , b: b
        , result: a - b
    });
});
You can’t perform that action at this time.