Prepend a sentinel value to model ids to distinguish them from normal UUIDs (from Sylvain Corlay).

Jason Grout 12 years ago
parent 0c72fddaba
commit eed0715a09

@ -213,7 +213,7 @@ define(["widgets/js/manager",
var that = this;
var packed;
if (value instanceof Backbone.Model) {
return value.id;
return "IPY_MODEL_" + value.id;
} else if ($.isArray(value)) {
packed = [];
@ -252,13 +252,15 @@ define(["widgets/js/manager",
});
return unpacked;
} else if (typeof value === 'string' && value.slice(0,10) === "IPY_MODEL_") {
var model = this.widget_manager.get_model(value.slice(10, value.length));
if (model) {
return model;
} else {
return value;
}
} else {
var model = this.widget_manager.get_model(value);
if (model) {
return model;
} else {
return value;
}
}
},

@ -322,7 +322,7 @@ class Widget(LoggingConfigurable):
elif isinstance(x, (list, tuple)):
return [self._serialize_trait(v) for v in x]
elif isinstance(x, Widget):
return x.model_id
return "IPY_MODEL_" + x.model_id
else:
return x # Value must be JSON-able
@ -335,7 +335,7 @@ class Widget(LoggingConfigurable):
return {k: self._unserialize_trait(v) for k, v in x.items()}
elif isinstance(x, (list, tuple)):
return [self._unserialize_trait(v) for v in x]
elif isinstance(x, string_types) and x in Widget.widgets:
elif isinstance(x, string_types) and x.startswith('IPY_MODEL_') and x[10:] in Widget.widgets:
# we want to support having child widgets at any level in a hierarchy
# trusting that a widget UUID will not appear out in the wild
return Widget.widgets[x]

Loading…
Cancel
Save