1.1.68 • Published 8 years ago

mototaxi v1.1.68

Weekly downloads
39
License
MIT
Repository
github
Last release
8 years ago

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

8 years ago

1.1.67

8 years ago

1.1.66

8 years ago

1.1.65

8 years ago

1.1.64

8 years ago

1.1.59

8 years ago

1.1.58

8 years ago

1.1.57

8 years ago

1.1.56

8 years ago

1.1.55

8 years ago

1.1.54

8 years ago

1.1.53

8 years ago

1.1.52

8 years ago

1.1.51

8 years ago

1.1.50

8 years ago

1.1.49

8 years ago

1.1.48

8 years ago

1.1.46

8 years ago

1.1.35

8 years ago

1.1.34

8 years ago

1.1.33

8 years ago

1.1.32

8 years ago

1.1.31

8 years ago

1.1.30

8 years ago

1.1.29

8 years ago

1.1.28

8 years ago

1.1.27

8 years ago

1.1.26

8 years ago

1.1.25

8 years ago

1.1.24

8 years ago

1.1.23

8 years ago

1.1.21

8 years ago

1.1.20

8 years ago

1.1.19

8 years ago

1.1.18

8 years ago

1.1.17

8 years ago

1.1.15

8 years ago

1.1.14

8 years ago

1.1.13

8 years ago

1.1.12

8 years ago

1.1.11

8 years ago

1.1.9

8 years ago

1.1.8

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago