MyAcc: variable renaming
[myslice.git] / manifold / static / js / buffer.js
1 /* Buffered DOM updates */
2 var Buffer = Class.extend({
3
4     init: function(callback, callback_this) {
5         this._callback = callback;
6         this._callback_this = callback_this;
7         this._timerid  = null;
8         this._num_elements = 0;
9         this._elements = Array();
10
11         this._interval = 1000;
12
13         return this;
14     },
15
16     add: function(element)
17     {
18         this._elements.push(element);
19         if (this._num_elements == 0) {
20             this._timerid = setInterval(
21                 (function(self) {         //Self-executing func which takes 'this' as self
22                     return function() {   //Return a function in the context of 'self'
23                         console.log("running callback");
24                         clearInterval(self._timerid);
25                         self._callback.apply(self._callback_this);
26                     }
27                 })(this),
28                 this._interval);
29         }
30         this._num_elements++;
31     },
32
33     get: function() {
34         var elements = this._elements;
35         this._elements = Array();
36         this._num_elements = 0;
37         return elements;
38     },
39
40 });