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(); + }); + }); });