-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample2.html
72 lines (63 loc) · 1.54 KB
/
example2.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
63
64
65
66
67
68
69
70
71
72
<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>
<a href="#" onclick={setRed}>Set Red</a>
<style scoped>
div {
width:100px;
height:100px;
border-radius:50%;
}
.red {
background-color:red;
}
.green {
background-color:green;
}
</style>
var self = this;
this.mixin('tsore');
this.attach('trafficLight',function(store){
self.color = store.getState();
});
click() {
tsore.action('Trigger');
};
setRed() {
tsore.action('SetState','red');
}
</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;
};
this.on('Trigger Show Hide'); // Declare Actions
// Event
this.on('SetState', function(color){
state = color;
tsore.trigger('change');
});
// Manually for all triggers
this.on(function(action){
if(action == 'Trigger') {
state = state == 'red'?'green':'red';
tsore.trigger('change');
}
});
}
);
tsore.register('trafficLight', trafficLight);
riot.mount('*');
</script>
</body>
</html>