diff options
-rw-r--r-- | examples/index.html | 66 | ||||
-rw-r--r-- | lib/dombatcher.js | 22 |
2 files changed, 43 insertions, 45 deletions
diff --git a/examples/index.html b/examples/index.html index 9424377..1b5c237 100644 --- a/examples/index.html +++ b/examples/index.html @@ -10,50 +10,48 @@ </style> </head> <body> - <div class='div1'></div> - <div class='div2'></div> - <div class='div3'></div> - <script type="text/javascript" src="../lib/dombatcher.js"></script> - <script> + <div class='div1'></div> + <div class='div2'></div> + <div class='div3'></div> + <script type="text/javascript" src="../lib/dombatcher.js"></script> + <script> + domBatch.write(function() { + console.log('write1'); + }); + domBatch.read(function() { + console.log('read1'); + }); - domBatch.write(function() { - console.log('write1'); - }); + domBatch.read(function() { + console.log('read1'); + }); - domBatch.read(function() { - console.log('read1'); - }); + domBatch.write(function() { + console.log('write1'); + }); - domBatch.read(function() { - console.log('read1'); - }); - domBatch.write(function() { - console.log('write1'); - }); + setTimeout(function() { + domBatch.write(function() { + console.log('write2'); + }); - setTimeout(function() { + domBatch.read(function() { + console.log('read2'); + }); - domBatch.write(function() { - console.log('write2'); - }); + domBatch.read(function() { + console.log('read2'); + }); - domBatch.read(function() { - console.log('read2'); - }); - - domBatch.read(function() { - console.log('read2'); - }); - - domBatch.write(function() { - console.log('write2'); - }); - }, 400); - </script> + domBatch.write(function() { + console.log('write2'); + }); + }, 400); + </script> </body> </html>
\ No newline at end of file diff --git a/lib/dombatcher.js b/lib/dombatcher.js index 07cba1a..190bb9c 100644 --- a/lib/dombatcher.js +++ b/lib/dombatcher.js @@ -6,24 +6,24 @@ var batch; function call(fns) { - var fn; - while (fn = fns.shift()) fn(); + var fn; + while (fn = fns.shift()) fn(); } domBatch.read = function(fn) { - batch = batch || setBatch(); - reads.push(fn); + batch = batch || setBatch(); + reads.push(fn); }; domBatch.write = function(fn) { - batch = batch || setBatch(); - writes.push(fn); + batch = batch || setBatch(); + writes.push(fn); }; function setBatch() { - return setTimeout(function() { - call(reads); - call(writes); - batch = null; - }, 0); + return setTimeout(function() { + call(reads); + call(writes); + batch = null; + }, 0); }
\ No newline at end of file |