diff options
author | Wilson Page <wilsonpage@me.com> | 2013-08-26 23:10:08 +0100 |
---|---|---|
committer | Wilson Page <wilsonpage@me.com> | 2013-08-26 23:10:08 +0100 |
commit | 1caabf4af5045c692bec2506f2e1d3410cf8f4f3 (patch) | |
tree | 0ad04aa3f6966c63d72b6676488b510225a25f66 /lib/dom-batch.js | |
parent | ec833e9221b5baca819d1657d40e2cb192599b6d (diff) | |
download | fastdom-1caabf4af5045c692bec2506f2e1d3410cf8f4f3.zip fastdom-1caabf4af5045c692bec2506f2e1d3410cf8f4f3.tar.gz fastdom-1caabf4af5045c692bec2506f2e1d3410cf8f4f3.tar.bz2 |
Implement clear API
Diffstat (limited to 'lib/dom-batch.js')
-rw-r--r-- | lib/dom-batch.js | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/lib/dom-batch.js b/lib/dom-batch.js index f4124ce..1e1bcb4 100644 --- a/lib/dom-batch.js +++ b/lib/dom-batch.js @@ -27,12 +27,9 @@ : new DomBatch(); /** - * Creates a new + * Creates a fresh * DomBatch instance. * - * (you should only have one - * instance per application). - * * @constructor */ function DomBatch() { @@ -67,6 +64,28 @@ }; /** + * Removes a job from + * the 'reads' queue. + * + * @param {Function} fn + * @api public + */ + DomBatch.prototype.clearRead = function(fn) { + remove(this.reads, fn); + }; + + /** + * Removes a job from + * the 'writes' queue. + * + * @param {Function} fn + * @api public + */ + DomBatch.prototype.clearWrite = function(fn) { + remove(this.writes, fn); + }; + + /** * Makes the decision as to * whether a the frame needs * to be scheduled. @@ -131,14 +150,13 @@ // that come in will schedule a new frame this.pending = false; - // Set the mode to 'reading' so - // that we know we can add more - // reads to the queue instead of - // scheduling a new frame. + // Set the mode to 'reading', + // then empty all read jobs this.mode = 'reading'; this.run(this.reads); - // Set + // Set the mode to 'writing' + // then empty all write jobs this.mode = 'writing'; this.run(this.writes); @@ -146,6 +164,15 @@ }; /** + * Util + */ + + function remove(array, item) { + var index = array.indexOf(item); + if (~index) array.splice(index, 1); + } + + /** * Expose 'DomBatch' */ |