-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
80 lines (63 loc) · 1.96 KB
/
index.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
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html>
<head>
<title>Porter Index</title>
</head>
<body>
<h1 id="groot1"></h1>
<h1 id="groot2"></h1>
<h1 id="groot3"></h1>
<script type="text/javascript" src="porter.js"></script>
<script type="text/javascript">
// grab an element
var e1 = document.getElementById("groot1");
var e2 = document.getElementById("groot2");
var e3 = document.getElementById("groot3");
//define an equipment list that renders on `update`
function EquipmentList(element ,state){
this.element = element;
this.update(state);
}
// update the object state and render().
EquipmentList.prototype.update = function(newState) {
this.state = newState;
this.render()
};
//update the element to with state to render
EquipmentList.prototype.render = function() {
this.element.innerText = this.state
}
// define an equipmentChannel and a helper function.
var equipmentChannel = new Channel("equipment");
function pushEquipmentListState(state) {
equipmentChannel.publish("state", state);
}
// make an instance of equipment list
var eq1 = new EquipmentList(e1, "GROOOOOOT");
var eq2 = new EquipmentList(e2, "not GROOOOOOT");
var eq3 = new EquipmentList(e3, 1);
equipmentChannel.subscribe("once", function(e) {
console.log("e.detail", e.detail);
console.log("e.copy()", e.copy());
});
// describe what should happen on the "state" event.
equipmentChannel.subscribe("state", function(e){
eq1.update(grab(e).eq1);
eq2.update(grab(e).eq2);
});
equipmentChannel.subscribe("eq3state", function(e){
eq3.update(grab(e));
});
console.log("eq3 is", eq3);
setInterval(function(e){
console.log(e);
equipmentChannel.publish("eq3state", -eq3.state);
}, 666);
// fire async events.
setInterval(function(){
pushEquipmentListState({eq1: Math.random(1), eq2: Math.random(1)});
}, 1000);
setTimeout(function(){equipmentChannel.publish("once", {"some": "info"})}, 1000);
</script>
</body>
</html>