forked from canjs/canjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.html
91 lines (71 loc) · 2.14 KB
/
map.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
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Memory Leak Test</title>
</head>
<body>
<button class="poll">Start Polling</button>
<button class="stop">Stop Polling</button><br/><br/>
<div id='live'></div>
<script id="dummyEJS" type="text/ejs">
<% stats.each(function(s) { %>
Name: <%= s.attr('name') %>: <%= s.attr('homeruns') %> (<%= s.getAverage() %>)<br/>
<% }) %>
</script>
<script src='../lib/steal/steal.js'></script>
<script type='text/javascript'>
steal('can',function(){
Stat = can.Model({
id: "name",
findAll: function(){
var def = $.Deferred();
setTimeout(function(){
def.resolve([
{
"id": 0,
"name": "Ryan Braun",
"homeruns": 2,
"atbats": 20,
"hits": 12
},
{
"id": 1,
"name": "Troy Tulowitzki",
"homeruns": 4,
"atbats": 20,
"hits": 8
}
])
},100)
return def;
}
}, {
getAverage: function() {
return (this.attr('hits') / this.attr('atbats')).toFixed(3);
}
});
window.counter = 0;
var poll = function () {
// Increment the counter
counter++;
// Fetch stats from server
Stat.findAll().then(function(stats) {
// Grab the stats model for Ryan Braun
var p = Stat.model({name: 'Ryan Braun'});
// Update his number of home runs to a random number
p.attr('homeruns', Math.floor(Math.random() * 60 + 1));
});
// Store the timer ID so we can cancel the polling
window.timeoutId = setTimeout(arguments.callee,200);
}
Stat.findAll().then(function(stats){
$("#live").append(can.view('dummyEJS', {
stats: stats
}))
poll();
})
});
</script>
</body>
</html>