Socket
Socket
Sign inDemoInstall

mototaxi

Package Overview
Dependencies
88
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

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.


Version published
Weekly downloads
61
increased by577.78%
Maintainers
1
Install size
71.1 MB
Created
Weekly downloads
 

Readme

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

Last updated on 10 Aug 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc