Skip to content

Commit 386eed2

Browse files
committed
Ensure dictionary type instance persistence
Adds an assignment function for dict types that preserves the dict instances on the three objects.
1 parent da559b1 commit 386eed2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

js/scripts/prop-types.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ _.extend(DictType.prototype, BaseType.prototype, {
364364
var nullableStr = this.nullable ? 'True' : 'False';
365365
return `Dict(default_value=${this.getPythonDefaultValue()}, allow_none=${nullableStr}).tag(sync=True)`;
366366
},
367+
getPropertyAssignmentFn: function() {
368+
return 'assignDict';
369+
},
367370
});
368371

369372
function FunctionType(fn) {

js/src/_base/Three.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,18 @@ var ThreeModel = widgets.WidgetModel.extend({
644644
return threeType.ipymodel;
645645
},
646646

647+
// Dict
648+
assignDict: function(obj, key, value) {
649+
if (obj[key] === value) {
650+
// If instance equality, do nothing.
651+
return;
652+
}
653+
// Clear the dict
654+
Object.keys(obj[key]).forEach(k => { delete obj[key][k]; });
655+
// Put in the new values
656+
Object.assign(obj[key], value);
657+
},
658+
647659
// ThreeTypeArray
648660
convertThreeTypeArrayModelToThree: function(modelArr, propName) {
649661
return modelArr.map(function(model) {

0 commit comments

Comments
 (0)