Commit f245293e by Romain Courteaud

No need to set default gadget state asynchronously.

1 parent be2d115f
......@@ -494,6 +494,9 @@
function clearGadgetInternalParameters(gadget) {
gadget.__sub_gadget_dict = {};
if (gadget.__json_state !== undefined) {
gadget.state = JSON.parse(gadget.__json_state);
}
createGadgetMonitor(gadget);
}
......@@ -545,10 +548,7 @@
return this;
};
RenderJSGadget.setState = function setState(state_dict) {
var json_state = JSON.stringify(state_dict);
this.__ready_list.unshift(function setStateDefaultValue() {
this.state = JSON.parse(json_state);
});
this.prototype.__json_state = JSON.stringify(state_dict);
return this;
};
RenderJSGadget.onStateChange = function onStateChange(callback) {
......
......@@ -1988,7 +1988,7 @@
equal(result, Klass);
});
test('create callback in the ready_list property', function () {
test('create __json_state property on prototype', function () {
// Subclass RenderJSGadget to not pollute its namespace
var Klass = function () {
RenderJSGadget.call(this);
......@@ -2000,29 +2000,7 @@
Klass.setState = RenderJSGadget.setState;
Klass.setState({foo: 'bar'});
equal(Klass.__ready_list.length, 1);
});
test('is called before other ready callbacks', function () {
// Subclass RenderJSGadget to not pollute its namespace
var Klass = function () {
RenderJSGadget.call(this);
},
ready_callback;
Klass.prototype = new RenderJSGadget();
Klass.prototype.constructor = Klass;
Klass.__ready_list = [];
Klass.ready = RenderJSGadget.ready;
Klass.setState = RenderJSGadget.setState;
Klass.ready(function () {
return;
});
ready_callback = Klass.__ready_list[0];
Klass.setState({foo: 'bar'});
equal(Klass.__ready_list.length, 2);
deepEqual(Klass.__ready_list[1], ready_callback);
equal(Klass.prototype.__json_state, JSON.stringify({foo: 'bar'}));
});
/////////////////////////////////////////////////////////////////
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!