diff options
author | Deryck <dhenson02@users.noreply.github.com> | 2016-06-06 03:54:38 -0400 |
---|---|---|
committer | Wilson Page <wilsonpage@me.com> | 2016-06-06 08:54:38 +0100 |
commit | b0262dd72772e0d2556c6d5c56da21321751d9cb (patch) | |
tree | 692418528ea39d43b72ac27e5ac34637a6a782e5 | |
parent | bbdc19189b3ac4308fd55a17571347fcfec9c72a (diff) | |
download | fastdom-b0262dd72772e0d2556c6d5c56da21321751d9cb.zip fastdom-b0262dd72772e0d2556c6d5c56da21321751d9cb.tar.gz fastdom-b0262dd72772e0d2556c6d5c56da21321751d9cb.tar.bz2 |
extract context binding from loop, apply when added (#84)
* extract context binding from loop, apply when added
* pass function as first param to mutate
* corrected to match other test cases
-rw-r--r-- | fastdom.js | 6 | ||||
-rw-r--r-- | test/fastdom-test.js | 2 |
2 files changed, 4 insertions, 4 deletions
@@ -56,7 +56,7 @@ FastDom.prototype = { */ measure: function(fn, ctx) { debug('measure'); - var task = { fn: fn, ctx: ctx }; + var task = !ctx ? fn : fn.bind(ctx); this.reads.push(task); scheduleFlush(this); return task; @@ -72,7 +72,7 @@ FastDom.prototype = { */ mutate: function(fn, ctx) { debug('mutate'); - var task = { fn: fn, ctx: ctx }; + var task = !ctx ? fn : fn.bind(ctx); this.writes.push(task); scheduleFlush(this); return task; @@ -203,7 +203,7 @@ function flush(fastdom) { */ function runTasks(tasks) { debug('run tasks'); - var task; while (task = tasks.shift()) task.fn.call(task.ctx); + var task; while (task = tasks.shift()) task(); } /** diff --git a/test/fastdom-test.js b/test/fastdom-test.js index 64f72e5..5dd4ceb 100644 --- a/test/fastdom-test.js +++ b/test/fastdom-test.js @@ -340,7 +340,7 @@ suite('fastdom', function() { test('it removes reference to the job if cleared', function(done) { var write = sinon.spy(); - var id = fastdom.mutate(2, write); + var id = fastdom.mutate(write); fastdom.clear(id); |