Commit bce5da91 by Romain Courteaud

Ensure state initialization is done before the ready callbacks.

1 parent 727a1ed8
......@@ -469,9 +469,10 @@
};
RenderJSGadget.setState = function (state_dict) {
var json_state = JSON.stringify(state_dict);
return this.ready(function () {
this.__ready_list.unshift(function () {
this.state = JSON.parse(json_state);
});
return this;
};
RenderJSGadget.onStateChange = function (callback) {
this.prototype.__state_change_callback = callback;
......
......@@ -1850,6 +1850,28 @@
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);
});
/////////////////////////////////////////////////////////////////
// RenderJSGadgetKlass.onStateChange
/////////////////////////////////////////////////////////////////
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!