diff options
author | Wilson Page <wilsonpage@me.com> | 2013-02-09 20:59:54 +0000 |
---|---|---|
committer | Wilson Page <wilsonpage@me.com> | 2013-02-09 20:59:54 +0000 |
commit | ba984ea043828076c7a3f88e598d3f31afb912a8 (patch) | |
tree | db6ee35609c416ce3244fa807d7fd27360ed517f /lib/dombatcher.js | |
download | fastdom-origin/0.1.zip fastdom-origin/0.1.tar.gz fastdom-origin/0.1.tar.bz2 |
First commit0.1origin/0.1
Diffstat (limited to 'lib/dombatcher.js')
-rw-r--r-- | lib/dombatcher.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/dombatcher.js b/lib/dombatcher.js new file mode 100644 index 0000000..fe5590e --- /dev/null +++ b/lib/dombatcher.js @@ -0,0 +1,37 @@ + +/** + * Util + */ + +function dispatch(fns) { + var fn; + while (fn = fns.shift()) fn(); +} + +/** + * Lib + */ + +function DomBatcher() { + this.reads = []; + this.writes = []; +} + +DomBatcher.prototype.read = function(fn) { + this._dispatcher = this._dispatcher || this.dispatch(); + this.reads.push(fn); +}; + +DomBatcher.prototype.write = function(fn) { + this._dispatcher = this._dispatcher || this.dispatch(); + this.writes.push(fn); +}; + +DomBatcher.prototype.dispatch = function() { + var self = this; + return setTimeout(function() { + dispatch(self.reads); + dispatch(self.writes); + delete self._dispatcher; + }, 0); +}; |