Skip to content

Commit

Permalink
Fix fastdom-strict callbacks not being called with context (fixes #108)…
Browse files Browse the repository at this point in the history
… (#109)
  • Loading branch information
Melatonin64 authored and wilsonpage committed May 2, 2017
1 parent 970bae9 commit 6424d55
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/fastdom-strict.js
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions test/fastdom-strict-test.js
Expand Up @@ -2,6 +2,7 @@
/*jshint maxlen:false*/

suite('fastdom-strict', function() {
var raf = window.requestAnimationFrame;
var fastdom;
var el;

Expand Down Expand Up @@ -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();
});
});
});

0 comments on commit 6424d55

Please sign in to comment.