Commit 95726c33 by Romain Courteaud

Prevent calling onStateChange callback if not needed

1 parent 32a5a8ef
......@@ -608,7 +608,6 @@
modified = true;
} else {
modification_dict = {};
this.__modification_dict = modification_dict;
}
for (key in state_dict) {
if (state_dict.hasOwnProperty(key) &&
......@@ -619,6 +618,7 @@
}
}
if (modified && this.__state_change_callback !== undefined) {
this.__modification_dict = modification_dict;
return new RSVP.Queue()
.push(function () {
return context.__state_change_callback(modification_dict);
......
......@@ -1328,6 +1328,30 @@
});
});
test('do not trigger onStateChange if no changed keys twice', function () {
var gadget = new RenderJSGadget(),
callback_called = false;
gadget.state = {};
gadget.__state_change_callback = function () {
callback_called = true;
};
stop();
gadget.changeState({})
.then(function () {
ok(!callback_called);
return gadget.changeState({});
})
.then(function () {
ok(!callback_called);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test('accumulate modification_dict on onStateChange error', function () {
var gadget = new RenderJSGadget();
expect(13);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!