Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow initial values for model attributes to be specified on creation of the models #383

Merged
merged 2 commits into from
Feb 22, 2016

Conversation

SylvainCorlay
Copy link
Member

  • The base widget model constructor now takes the standard backbonejs attributes argument so that we can create widget models with initial values.
  • The private helper function _deserialize_state is now a class method. We need that so that we can deserialize state before instantiating the model, and pass the full deserialized state to the model constructors.
  • A consequence is that _deserialize_state cannot take the model instance as a second argument anymore. And therefore, the same is also true for the custom serializers. Custom deserializers were actually not using this second argument, except the model deserialization (IPY_MODEL_*** to model instance) which in fact only needed a reference to the widget manager. Hence, the second argument passed to _deserialize_state and the custom serializers is now the widget manager itself.
  • The _first_state attribute has been removed from the base model, simplifying our overload of backbone.Model.set.
  • The widget controller does not use the ready event that was removed since it is not needed anymore. This should solve the last issues with Controller widget persistence.

This is a negative contribution in the number of lines, so a good sign!

@SylvainCorlay SylvainCorlay force-pushed the no_first_state branch 2 times, most recently from 62a2576 to 99ccc93 Compare February 21, 2016 22:20
@SylvainCorlay
Copy link
Member Author

@jdfreder this seems to complete the blocking issue on persistence for widgets created from the front-end.

@SylvainCorlay SylvainCorlay changed the title No first state Allow initial values for model attributes to be specified on creation of the models Feb 21, 2016
@SylvainCorlay SylvainCorlay added this to the 5.0 milestone Feb 22, 2016
@minrk
Copy link
Contributor

minrk commented Feb 22, 2016

I like the resulting centralization of deserialization here. 👍

@jdfreder
Copy link
Contributor

Nice, this is great cleanup @SylvainCorlay !

jdfreder added a commit that referenced this pull request Feb 22, 2016
Allow initial values for model attributes to be specified on creation of the models
@jdfreder jdfreder merged commit ee2359f into jupyter-widgets:master Feb 22, 2016
@blink1073
Copy link
Contributor

🎉

@@ -194,7 +172,7 @@ var WidgetModel = Backbone.Model.extend({
for (var i=0; i<buffer_keys.length; i++) {
state[buffer_keys[i]] = buffers[i];
}
return that._deserialize_state(state);
return that.constructor._deserialize_state(state, that.manager);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be that.widget_manager?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, see #388

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 👍

jdfreder added a commit to jdfreder/ipywidgets that referenced this pull request Feb 22, 2016
@jdfreder jdfreder mentioned this pull request Feb 22, 2016
@SylvainCorlay SylvainCorlay deleted the no_first_state branch February 22, 2016 23:46
@github-actions github-actions bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Feb 25, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants