summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomer Lahav <Melatonin64@users.noreply.github.com>2017-05-02 03:54:05 -0400
committerWilson Page <wilsonpage@me.com>2017-05-02 08:54:05 +0100
commit6424d555db9af29295a5a21178eb8cfa2d83eec4 (patch)
treea04350d3546c5b1979ce0ffe4dc2869716242fe3
parent970bae9afb9cbde0b6484e57794c94467b44f549 (diff)
downloadfastdom-6424d555db9af29295a5a21178eb8cfa2d83eec4.zip
fastdom-6424d555db9af29295a5a21178eb8cfa2d83eec4.tar.gz
fastdom-6424d555db9af29295a5a21178eb8cfa2d83eec4.tar.bz2
Fix fastdom-strict callbacks not being called with context (fixes #108) (#109)
-rw-r--r--src/fastdom-strict.js6
-rw-r--r--test/fastdom-strict-test.js18
2 files changed, 22 insertions, 2 deletions
diff --git a/src/fastdom-strict.js b/src/fastdom-strict.js
index 86d3f4e..d26b86f 100644
--- a/src/fastdom-strict.js
+++ b/src/fastdom-strict.js
@@ -18,16 +18,18 @@ var debug = 0 ? console.log.bind(console, '[fastdom-strict]') : function() {};
var enabled = false;
window.fastdom = module.exports = fastdom.extend({
- measure: function(task, ctx) {
+ measure: function(fn, ctx) {
debug('measure');
+ var task = !ctx ? fn : fn.bind(ctx);
return this.fastdom.measure(function() {
if (!enabled) return task();
return strictdom.phase('measure', task);
}, ctx);
},
- mutate: function(task, ctx) {
+ mutate: function(fn, ctx) {
debug('mutate');
+ var task = !ctx ? fn : fn.bind(ctx);
return this.fastdom.mutate(function() {
if (!enabled) return task();
return strictdom.phase('mutate', task);
diff --git a/test/fastdom-strict-test.js b/test/fastdom-strict-test.js
index 688e8b2..d7c5779 100644
--- a/test/fastdom-strict-test.js
+++ b/test/fastdom-strict-test.js
@@ -2,6 +2,7 @@
/*jshint maxlen:false*/
suite('fastdom-strict', function() {
+ var raf = window.requestAnimationFrame;
var fastdom;
var el;
@@ -75,4 +76,21 @@ suite('fastdom-strict', function() {
el.clientWidth;
}).then(done);
});
+
+ test('callback is called with correct context when measuring and mutating', function(done) {
+ var ctx1 = { foo: 'bar' };
+ var ctx2 = { bar: 'baz' };
+
+ var spy1 = sinon.spy();
+ var spy2 = sinon.spy();
+
+ fastdom.measure(spy1, ctx1);
+ fastdom.mutate(spy2, ctx2);
+
+ raf(function() {
+ assert(spy1.calledOn(ctx1));
+ assert(spy2.calledOn(ctx2));
+ done();
+ });
+ });
});