Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mototaxi

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mototaxi

A support library for commands and handlers in existing or 'could be' CQRS systems.

  • 1.1.68
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Mototaxi

Installation: npm install --save mototaxi

Usage:


//We should have some command handlers...
const sopranoHandler = {
    harmony: (command) => {
        console.log(`Singing the soprano part of ${command.song}. La la la LA!`);
        return { type: 'songFinished', name: command.song };
    }
}

const altoHandler = {
    harmony: (command) => {
        console.log(`Singing the alto part of ${command.song}. La la LA la!`);
        return { type: 'songFinished', name: command.song };
    }
}

const tenorHandler = {
    harmony: (command) => {
        console.log(`Singing the tenor part of ${command.song}. La LA la la!`);
        return { type: 'songFinished', name: command.song };
    }
}

const bassHandler = {
    harmony: (command) => {
        console.log(`Singing the bass part of ${command.song}. LA la la la!`);
        return { type: 'songFinished', name: command.song };
    }
}

const soloHandler = {
    solo: (command) => {
        console.log(`Singing the big solo. Laaaaaa laaaa la la!`);
        return { name: command.song };
    }
}

//Need to get a dispatcher, preloaded with all the command handlers...
const motoTaxi = require('mototaxi');
const commandHandlers = [ sopranoHandler, altoHandler, tenorHandler, bassHandler, soloHandler ];
const dispatcher = mototaxi.getDispatcher(commandHandlers);

//Now, we can dispatch commands without caring what handlers might or might not handle them!
dispatcher
    .dispatch({ type: 'solo' })
    .subscribe((s) => { console.log(s.name); });

dispatcher
    .dispatch({ type: 'harmony', song: 'Free Bird' })
    .filter((e) => e.type==='songFinished')
    .subscribe((s) => { console.log(s.name); });

dispatcher
    .dispatch({ type: 'solo' })
    .subscribe((s) => { console.log(s.name); });

Keywords

FAQs

Package last updated on 10 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc