1.0.7 • Published 5 years ago

simple-command-bus v1.0.7

Weekly downloads
435
License
MIT
Repository
github
Last release
5 years ago

Simple Command Bus

npm version Build Status codecov

Simple Command Bus Implementation for NodeJS. It is majorly inspired by Tactician Command Bus for PHP https://tactician.thephpleague.com/

Requirements

This project requires nodejs 8 or higher.

Install

NPM

npm install simple-command-bus

Yarn

yarn add simple-command-bus

Basic Usage

const {
	Command,
	CommandBus,
	CommandHandlerMiddleware,
	ClassNameExtractor,
	InMemoryLocator,
	HandleInflector,
	LoggerMiddleware 
} = require('simple-command-bus');

// CreateAccount Command
class CreateAccountCommand extends Command {
	constructor(firstName, lastName) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
	}
}

// CreateAccount Handler
class CreateAccountHandler {
	handle(command) {
		// Logic to create an account.
	}
};

// Handler middleware
var commandHandlerMiddleware = new CommandHandlerMiddleware(
	new ClassNameExtractor(),
	new InMemoryLocator({ CreateAccountHandler: new CreateAccountHandler() }),
	new HandleInflector()
);

// Command bus instance
var commandBus = new CommandBus([
	new LoggerMiddleware(console),
	commandHandlerMiddleware
]);

const createAccountCommand = new CreateAccountCommand('John', 'Doe');
var result = commandBus.handle(createAccountCommand);
console.log('Result:', result);

Run tests

yarn run test

Run tests with coverage

yarn run test:coverage

Check example

  • node examples/index.js
1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago