UNPKG

can

Version:

MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.

91 lines (71 loc) 2.23 kB
<!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="../node_modules/steal/steal.js" main="@empty"></script> <script type='text/javascript'> steal('can', 'can/view/ejs', 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>