神刀安全网

A simple ESB implementation using EventEmitter

A simple ESB implementation using EventEmitter A simple ESB implementation using EventEmitter A simple ESB implementation using EventEmitter

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

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » A simple ESB implementation using EventEmitter

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮