summaryrefslogtreecommitdiffstats
path: root/lib/dom-batch.js
diff options
context:
space:
mode:
authorWilson Page <wilsonpage@me.com>2013-08-26 15:13:34 -0700
committerWilson Page <wilsonpage@me.com>2013-08-26 15:13:34 -0700
commitee451fcea25864445f30e6fd45eff4a1e186c773 (patch)
treeedb33c2f2957d6bf859bc3ac8945c8d84b450389 /lib/dom-batch.js
parent74740e46ec7fda5f5bfc44d4e2af6d5c9cfea9be (diff)
parent0af7a37e707456081b86e21d84a592dcf92048de (diff)
downloadfastdom-ee451fcea25864445f30e6fd45eff4a1e186c773.zip
fastdom-ee451fcea25864445f30e6fd45eff4a1e186c773.tar.gz
fastdom-ee451fcea25864445f30e6fd45eff4a1e186c773.tar.bz2
Merge pull request #4 from wilsonpage/dev
Implement clear API (closes #1)
Diffstat (limited to 'lib/dom-batch.js')
-rw-r--r--lib/dom-batch.js45
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'
*/