Skip to content

Commit 27fe4ca

Browse files
committed
Ensure three dicts propagate change events
1 parent 774b093 commit 27fe4ca

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

js/src/_base/Three.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var ThreeModel = widgets.WidgetModel.extend({
6969
this.listenTo(curValue, 'childchange', this.onChildChanged);
7070
}
7171

72-
// make sure to un/hook listeners when child points to new object
72+
// make sure to (un)hook listeners when child points to new object
7373
this.on('change:' + propName, function(model, value, options) {
7474
var prevModel = this.previous(propName);
7575
var currModel = value;
@@ -93,7 +93,7 @@ var ThreeModel = widgets.WidgetModel.extend({
9393
this.listenTo(childModel, 'childchange', this.onChildChanged);
9494
}, this);
9595

96-
// make sure to un/hook listeners when array changes
96+
// make sure to (un)hook listeners when array changes
9797
this.on('change:' + propName, function(model, value, options) {
9898
var prevArr = this.previous(propName) || [];
9999
var currArr = value || [];
@@ -111,7 +111,42 @@ var ThreeModel = widgets.WidgetModel.extend({
111111
}, this);
112112
}, this);
113113

114-
// TODO: handle dicts of children via this.three_dict_properties
114+
// Handle changes in three instance dict props
115+
this.three_dict_properties.forEach(function(propName) {
116+
117+
var currDict = this.get(propName) || {};
118+
119+
// listen to current values in dict
120+
var childModel;
121+
Object.keys(currDict).forEach(function(childModelKey) {
122+
childModel = currDict[childModelKey];
123+
this.listenTo(childModel, 'change', this.onChildChanged);
124+
this.listenTo(childModel, 'childchange', this.onChildChanged);
125+
}, this);
126+
127+
// make sure to (un)hook listeners when dict changes
128+
this.on('change:' + propName, function(model, value, options) {
129+
var prevDict = this.previous(propName) || {};
130+
var currDict = value || {};
131+
132+
var prevKeys = Object.keys(prevDict);
133+
var currKeys = Object.keys(currDict);
134+
135+
var added = _.difference(currKeys, prevKeys);
136+
var removed = _.difference(prevKeys, currKeys);
137+
138+
added.forEach(function(childModelKey) {
139+
childModel = currDict[childModelKey];
140+
this.listenTo(childModel, 'change', this.onChildChanged);
141+
this.listenTo(childModel, 'childchange', this.onChildChanged);
142+
}, this);
143+
removed.forEach(function(childModelKey) {
144+
childModel = prevDict[childModelKey];
145+
this.stopListening(childModel);
146+
}, this);
147+
}, this);
148+
149+
}, this);
115150

116151
this.on('change', this.onChange, this);
117152
this.on('msg:custom', this.onCustomMessage, this);

js/src/textures/DataTexture.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ var DataTextureModel = DataTextureBase.extend({
1919
throw Error('DataTexture data dimensions need to be 2 or 3, got:', rawData.dimension)
2020
}
2121
var data = this.convertArrayBufferModelToThree(rawData, 'data');
22-
var width = rawData.shape[0];
23-
var height = rawData.shape[1];
2422

2523
return {
2624
data: data,

0 commit comments

Comments
 (0)