summaryrefslogtreecommitdiffstats
path: root/lib/dom-batch.js
diff options
context:
space:
mode:
authorWilson Page <wilsonpage@me.com>2013-03-06 16:52:03 +0000
committerWilson Page <wilsonpage@me.com>2013-03-06 16:52:03 +0000
commit1d4f4eeb88ef6252df611994bcf9daa85416581b (patch)
tree9ccaff01cfb7d8f06cb300185a4de484810f066f /lib/dom-batch.js
parent4bf5df4ecb555adc27a0b342f6439c7958713705 (diff)
downloadfastdom-1d4f4eeb88ef6252df611994bcf9daa85416581b.zip
fastdom-1d4f4eeb88ef6252df611994bcf9daa85416581b.tar.gz
fastdom-1d4f4eeb88ef6252df611994bcf9daa85416581b.tar.bz2
Updated lib filename
Diffstat (limited to 'lib/dom-batch.js')
-rw-r--r--lib/dom-batch.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/dom-batch.js b/lib/dom-batch.js
new file mode 100644
index 0000000..e1cd5d7
--- /dev/null
+++ b/lib/dom-batch.js
@@ -0,0 +1,38 @@
+(function() {
+ var batcher = {};
+ var reads = [];
+ var writes = [];
+ var batch;
+
+ function call(fns) {
+ var fn;
+ while (fn = fns.shift()) fn();
+ }
+
+ domBatch.read = function(fn) {
+ batch = batch || setBatch();
+ reads.push(fn);
+ };
+
+ domBatch.write = function(fn) {
+ batch = batch || setBatch();
+ writes.push(fn);
+ };
+
+ function setBatch() {
+ return setTimeout(function() {
+ call(reads);
+ call(writes);
+ batch = null;
+ }, 0);
+ }
+
+ // Expose the library
+ if (typeof exports === "object") {
+ module.exports = batcher;
+ } else if (typeof define === "function" && define.amd) {
+ define(batcher);
+ } else {
+ window['batcher'] = batcher;
+ }
+}()); \ No newline at end of file