1.1.68 • Published 7 years ago
mototaxi v1.1.68
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
7 years ago
1.1.67
7 years ago
1.1.66
7 years ago
1.1.65
7 years ago
1.1.64
7 years ago
1.1.59
7 years ago
1.1.58
7 years ago
1.1.57
7 years ago
1.1.56
7 years ago
1.1.55
7 years ago
1.1.54
7 years ago
1.1.53
7 years ago
1.1.52
7 years ago
1.1.51
7 years ago
1.1.50
7 years ago
1.1.49
7 years ago
1.1.48
7 years ago
1.1.46
7 years ago
1.1.35
7 years ago
1.1.34
7 years ago
1.1.33
7 years ago
1.1.32
7 years ago
1.1.31
7 years ago
1.1.30
7 years ago
1.1.29
7 years ago
1.1.28
7 years ago
1.1.27
7 years ago
1.1.26
7 years ago
1.1.25
7 years ago
1.1.24
7 years ago
1.1.23
7 years ago
1.1.21
7 years ago
1.1.20
7 years ago
1.1.19
7 years ago
1.1.18
7 years ago
1.1.17
7 years ago
1.1.15
7 years ago
1.1.14
7 years ago
1.1.13
7 years ago
1.1.12
7 years ago
1.1.11
7 years ago
1.1.9
7 years ago
1.1.8
7 years ago
1.1.5
7 years ago
1.1.4
7 years ago