-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (60 loc) · 1.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import rosmaro from 'rosmaro';
import {partialReturns, typeHandler, defaultHandler} from 'rosmaro-binding-utils';
const handler = plan => partialReturns(typeHandler({defaultHandler})(plan));
const graph = {
"main": {
"type": "graph",
"nodes": {
"Prince": "Prince",
"Frog": "Frog"
},
"arrows": {
"Prince": {
"ate a pizza": {
"target": "Frog",
"entryPoint": "start"
}
}
},
"entryPoints": {
"start": {
"target": "Prince",
"entryPoint": "start"
}
}
},
"Prince": {
"type": "leaf"
},
"Frog": {
"type": "leaf"
}
};
const Frog = handler({
INTRODUCE_YOURSELF: () => "Ribbit! Ribbit!",
});
const Prince = handler({
INTRODUCE_YOURSELF: () => "I am The Prince of Rosmaro!",
EAT: ({action}) => action.dish === 'pizza' ? {arrow: 'ate a pizza'} : undefined
});
const bindings = {
'main': {handler: defaultHandler},
'main:Prince': {handler: Prince},
'main:Frog': {handler: Frog},
};
const model = rosmaro({graph, bindings});
let state;
[
{type: 'INTRODUCE_YOURSELF'},
{type: 'EAT', dish: 'yakisoba'},
{type: 'INTRODUCE_YOURSELF'},
{type: 'EAT', dish: 'pizza'},
{type: 'INTRODUCE_YOURSELF'}
].forEach(action => console.log(
({state} = model({state, action})).result.data
));
// I am The Prince of Rosmaro!
// undefined
// I am The Prince of Rosmaro!
// undefined
// Ribbit! Ribbit!