-
Notifications
You must be signed in to change notification settings - Fork 0
/
stop-when-test.html
41 lines (33 loc) · 1 KB
/
stop-when-test.html
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
<html>
<head>
<meta charset="utf-8">
<script src='flapjax/flapjax-impl.js'></script>
<script src='flapjax-world.js'></script>
</head>
<body>
<div id='timer'></div>
</body>
<script>
var on_tick = timerB(1000).changes();
var on_click = clicksE('timer');
var w = worldB(
0,
[ [on_tick, function(w, _) { return w + 1; }],
[on_click, function(w, _) { return 0; }] ]
);
var stopWhen = function(v) { return v > 3; }
var stopped = w.changes().collectE({state: 'run'}, function(wValue, acc) {
switch(acc.state) {
case 'run':
return {state: stopWhen(wValue) ? 'stopnext' : 'run', value: wValue};
case 'stopnext':
case 'stop':
return {state: 'stop', value: acc.value};
}
})
.filterE(function(v) { return v.state === 'run' || v.state === 'stopnext'; })
.mapE(function(v) { return v.value; }).startsWith(0);
var to_draw = stopped.liftB(P);
insertDomB(to_draw, getObj('timer'), 'end');
</script>
</html>