##// END OF EJS Templates
Prepend a sentinel value to model ids to distinguish them from normal UUIDs (from Sylvain Corlay).
Jason Grout -
Show More
@@ -213,7 +213,7 b' define(["widgets/js/manager",'
213 var that = this;
213 var that = this;
214 var packed;
214 var packed;
215 if (value instanceof Backbone.Model) {
215 if (value instanceof Backbone.Model) {
216 return value.id;
216 return "IPY_MODEL_" + value.id;
217
217
218 } else if ($.isArray(value)) {
218 } else if ($.isArray(value)) {
219 packed = [];
219 packed = [];
@@ -252,13 +252,15 b' define(["widgets/js/manager",'
252 });
252 });
253 return unpacked;
253 return unpacked;
254
254
255 } else if (typeof value === 'string' && value.slice(0,10) === "IPY_MODEL_") {
256 var model = this.widget_manager.get_model(value.slice(10, value.length));
257 if (model) {
258 return model;
259 } else {
260 return value;
261 }
255 } else {
262 } else {
256 var model = this.widget_manager.get_model(value);
257 if (model) {
258 return model;
259 } else {
260 return value;
263 return value;
261 }
262 }
264 }
263 },
265 },
264
266
@@ -322,7 +322,7 b' class Widget(LoggingConfigurable):'
322 elif isinstance(x, (list, tuple)):
322 elif isinstance(x, (list, tuple)):
323 return [self._serialize_trait(v) for v in x]
323 return [self._serialize_trait(v) for v in x]
324 elif isinstance(x, Widget):
324 elif isinstance(x, Widget):
325 return x.model_id
325 return "IPY_MODEL_" + x.model_id
326 else:
326 else:
327 return x # Value must be JSON-able
327 return x # Value must be JSON-able
328
328
@@ -335,7 +335,7 b' class Widget(LoggingConfigurable):'
335 return {k: self._unserialize_trait(v) for k, v in x.items()}
335 return {k: self._unserialize_trait(v) for k, v in x.items()}
336 elif isinstance(x, (list, tuple)):
336 elif isinstance(x, (list, tuple)):
337 return [self._unserialize_trait(v) for v in x]
337 return [self._unserialize_trait(v) for v in x]
338 elif isinstance(x, string_types) and x in Widget.widgets:
338 elif isinstance(x, string_types) and x.startswith('IPY_MODEL_') and x[10:] in Widget.widgets:
339 # we want to support having child widgets at any level in a hierarchy
339 # we want to support having child widgets at any level in a hierarchy
340 # trusting that a widget UUID will not appear out in the wild
340 # trusting that a widget UUID will not appear out in the wild
341 return Widget.widgets[x]
341 return Widget.widgets[x]
General Comments 0
You need to be logged in to leave comments. Login now