##// 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 213 var that = this;
214 214 var packed;
215 215 if (value instanceof Backbone.Model) {
216 return value.id;
216 return "IPY_MODEL_" + value.id;
217 217
218 218 } else if ($.isArray(value)) {
219 219 packed = [];
@@ -252,13 +252,15 b' define(["widgets/js/manager",'
252 252 });
253 253 return unpacked;
254 254
255 } else {
256 var model = this.widget_manager.get_model(value);
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 257 if (model) {
258 258 return model;
259 259 } else {
260 260 return value;
261 261 }
262 } else {
263 return value;
262 264 }
263 265 },
264 266
@@ -322,7 +322,7 b' class Widget(LoggingConfigurable):'
322 322 elif isinstance(x, (list, tuple)):
323 323 return [self._serialize_trait(v) for v in x]
324 324 elif isinstance(x, Widget):
325 return x.model_id
325 return "IPY_MODEL_" + x.model_id
326 326 else:
327 327 return x # Value must be JSON-able
328 328
@@ -335,7 +335,7 b' class Widget(LoggingConfigurable):'
335 335 return {k: self._unserialize_trait(v) for k, v in x.items()}
336 336 elif isinstance(x, (list, tuple)):
337 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 339 # we want to support having child widgets at any level in a hierarchy
340 340 # trusting that a widget UUID will not appear out in the wild
341 341 return Widget.widgets[x]
General Comments 0
You need to be logged in to leave comments. Login now