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