1.0.19 • Published 4 years ago

command-bus-ts v1.0.19

Weekly downloads
18
License
MIT
Repository
github
Last release
4 years ago

Command-bus-ts

npm type definitions npm npm npm bundle size node-current (tag) David David

Build Status Known Vulnerabilities Maintainability Test Coverage GitHub issues GitHub

This project provide a simple and decoupled solution from a command handle structure with supports of publish subscribe.

class

Usage

Install

npm i command-bus-ts

Basic Usage

var CommandBus = require('command-bus-ts').CommandBus
var test = new CommandBus();

test
    .registerCommand('ok', {
      execute: (...req) => {
          return 'done'
      }
    })
    .use((req, next) => {
      req.x = 'xxx';
      console.log('global Middleware', req);
      next();
    })
    .use((req, next) => {
      req.y = 'yyy';
      console.log('local Middleware', req);
      next();
    }, 'ok')
    .use((req, next) => {
      req.handle.execute(req);
      req.handle.execute = function(test){
        console.log('changed')
        return 'done changed';
      }
      console.log('local Middleware change handle', req);
      next();
    }, 'ok')
    .subscribeCommand('ok', {
      update: (subject) => {
        console.log('alert', subject);
      }
    });
    const res = test.execute(
    {
      commandName: 'ok',
      aaa: 1
    });
/**
  global Middleware {
  command: { commandName: 'ok', aaa: 1 },
  commandName: 'ok',
  handle: { execute: [Function: execute] },
  middlewares: [ [Function], [Function] ],
  listners: DefaultPublisher { subscribers: Set { [Object] } },
  x: 'xxx'
}
local Middleware {
  command: { commandName: 'ok', aaa: 1 },
  commandName: 'ok',
  handle: { execute: [Function: execute] },
  middlewares: [ [Function], [Function] ],
  listners: DefaultPublisher { subscribers: Set { [Object] } },
  x: 'xxx',
  y: 'yyy'
}
local Middleware change handle {
  command: { commandName: 'ok', aaa: 1 },
  commandName: 'ok',
  handle: { execute: [Function] },
  middlewares: [ [Function], [Function] ],
  listners: DefaultPublisher { subscribers: Set { [Object] } },
  x: 'xxx',
  y: 'yyy'
}
changed
alert {
  req: { commandName: 'ok', aaa: 1 },
  res: 'done changed',
  error: undefined
}
response of done changed
**/

see more in docs

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago