Commit 95726c33 authored by Romain Courteaud's avatar Romain Courteaud

Prevent calling onStateChange callback if not needed

parent 32a5a8ef
...@@ -608,7 +608,6 @@ ...@@ -608,7 +608,6 @@
modified = true; modified = true;
} else { } else {
modification_dict = {}; modification_dict = {};
this.__modification_dict = modification_dict;
} }
for (key in state_dict) { for (key in state_dict) {
if (state_dict.hasOwnProperty(key) && if (state_dict.hasOwnProperty(key) &&
...@@ -619,6 +618,7 @@ ...@@ -619,6 +618,7 @@
} }
} }
if (modified && this.__state_change_callback !== undefined) { if (modified && this.__state_change_callback !== undefined) {
this.__modification_dict = modification_dict;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return context.__state_change_callback(modification_dict); return context.__state_change_callback(modification_dict);
......
...@@ -1328,6 +1328,30 @@ ...@@ -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 () { test('accumulate modification_dict on onStateChange error', function () {
var gadget = new RenderJSGadget(); var gadget = new RenderJSGadget();
expect(13); expect(13);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment