-
Notifications
You must be signed in to change notification settings - Fork 1
/
example1.html
62 lines (56 loc) · 1.34 KB
/
example1.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<html>
<body>
<h1>Click the Traffic Light<h1>
<traffic-lignt></traffic-lignt>
<script type="riot/tag">
<traffic-lignt>
<div class={color=='red'?"red":"green"} onclick={click}></div>
<style scoped>
div {
width:100px;
height:100px;
border-radius:50%;
}
.red {
background-color:red;
}
.green {
background-color:green;
}
</style>
var self = this;
this.color = tsore.store('trafficLight').getState();
click() {
tsore.action('Trigger');
};
tsore.on('change',function(){
self.color = tsore.store('trafficLight').getState();
self.update();
});
</traffic-lignt>
</script>
<script src="riot+compiler.js"></script>
<script src="tsore.js"></script>
<script>
var trafficLight = new tsore.Store(
function(){
var state = 'red';
this.getState = function(){
return state;
};
// Event
this.on('Trigger', function(){
state = state == 'red'?'green':'red';
tsore.trigger('change');
});
// For all triggers
this.on(function(action){
console.log(action, state);
});
}
);
tsore.register('trafficLight', trafficLight);
riot.mount('*');
</script>
</body>
</html>