summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilson Page <wilsonpage@me.com>2013-10-14 17:46:35 +0100
committerWilson Page <wilsonpage@me.com>2013-10-14 17:46:35 +0100
commitc00b6dd2c50abcfd01c1e2397ebdbb96afb0afee (patch)
treee74caf2207d092f82c126022ab46321b255a443a
parentff502b0661e8ad3a04cfdbda0e6ee53d7cdda01e (diff)
downloadfastdom-c00b6dd2c50abcfd01c1e2397ebdbb96afb0afee.zip
fastdom-c00b6dd2c50abcfd01c1e2397ebdbb96afb0afee.tar.gz
fastdom-c00b6dd2c50abcfd01c1e2397ebdbb96afb0afee.tar.bz2
Make a differentiation between the read.write batch and the frame queue
-rw-r--r--index.js40
-rw-r--r--test/test.clear.js2
-rw-r--r--test/test.set.js4
3 files changed, 26 insertions, 20 deletions
diff --git a/index.js b/index.js
index 7efb9d5..a077c06 100644
--- a/index.js
+++ b/index.js
@@ -41,7 +41,7 @@
this.frames = [];
this.lastId = 0;
this.mode = null;
- this.queue = {
+ this.batch = {
hash: {},
read: [],
write: []
@@ -49,8 +49,9 @@
}
/**
- * Adds a job to
- * the read queue.
+ * Adds a job to the
+ * write batch and schedules
+ * a new frame if need be.
*
* @param {Function} fn
* @api public
@@ -58,7 +59,7 @@
FastDom.prototype.read = function(fn, ctx) {
var job = this.add('read', fn, ctx);
- this.queue.read.push(job.id);
+ this.batch.read.push(job.id);
// If we're writing and a 'read' job
// comes in, we do have to schedule a new frame
@@ -71,8 +72,9 @@
};
/**
- * Adds a job to
- * the write queue.
+ * Adds a job to the
+ * write batch and schedules
+ * a new frame if need be.
*
* @param {Function} fn
* @api public
@@ -80,10 +82,10 @@
FastDom.prototype.write = function(fn, ctx) {
var job = this.add('write', fn, ctx);
- this.queue.write.push(job.id);
+ this.batch.write.push(job.id);
// If we're emptying the read
- // queue and a write comes in,
+ // batch and a write comes in,
// we don't need to schedule a
// new frame. If we're writing
// and write comes in we don't
@@ -101,6 +103,10 @@
* by the number of frames
* specified.
*
+ * If no frames are given
+ * then the job is run in
+ * the next free frame.
+ *
* @param {Number} frame
* @param {Function} fn
* @api public
@@ -139,14 +145,14 @@
return this.clearFrame(id);
}
- var job = this.queue.hash[id];
+ var job = this.batch.hash[id];
if (!job) return;
- var list = this.queue[job.type];
+ var list = this.batch[job.type];
var index = list.indexOf(id);
// Clear references
- delete this.queue.hash[id];
+ delete this.batch.hash[id];
if (~index) list.splice(index, 1);
};
@@ -207,7 +213,7 @@
FastDom.prototype.flush = function(list) {
var id;
while (id = list.shift()) {
- this.run(this.queue.hash[id]);
+ this.run(this.batch.hash[id]);
}
};
@@ -222,19 +228,19 @@
// Set the mode to 'reading',
// then empty all read jobs
this.mode = 'reading';
- this.flush(this.queue.read);
+ this.flush(this.batch.read);
// Set the mode to 'writing'
// then empty all write jobs
this.mode = 'writing';
- this.flush(this.queue.write);
+ this.flush(this.batch.write);
this.mode = null;
};
/**
* Adds a new job to
- * the given queue.
+ * the given batch.
*
* @param {Array} list
* @param {Function} fn
@@ -244,7 +250,7 @@
*/
FastDom.prototype.add = function(type, fn, ctx) {
var id = this.uniqueId();
- return this.queue.hash[id] = {
+ return this.batch.hash[id] = {
id: id,
fn: fn,
ctx: ctx,
@@ -262,7 +268,7 @@
var ctx = job.ctx || this;
// Clear reference to the job
- delete this.queue.hash[job.id];
+ delete this.batch.hash[job.id];
if (this.quiet) {
try { job.fn.call(ctx); } catch (e) {}
diff --git a/test/test.clear.js b/test/test.clear.js
index bea8031..f0f60b1 100644
--- a/test/test.clear.js
+++ b/test/test.clear.js
@@ -87,7 +87,7 @@ suite('clear', function(){
raf(function() {
raf(function() {
assert(!write.called);
- assert(!fastdom.queue.hash[id]);
+ assert(!fastdom.batch.hash[id]);
done();
});
});
diff --git a/test/test.set.js b/test/test.set.js
index f5b2ae3..a41259a 100644
--- a/test/test.set.js
+++ b/test/test.set.js
@@ -146,10 +146,10 @@ suite('set', function() {
fastdom.write(function(){});
// Check there are four jobs stored
- assert.equal(objectLength(fastdom.queue.hash), 4);
+ assert.equal(objectLength(fastdom.batch.hash), 4);
raf(function() {
- assert.equal(objectLength(fastdom.queue.hash), 0);
+ assert.equal(objectLength(fastdom.batch.hash), 0);
done();
});
});