Skip to content

Commit ac691c0

Browse files
committed
Imrpove syncToModel
Ensures all properties are set in the same call to backbone (expect mapped properties). Also tags with 'pushFromThree' to prevent an automatic call to syncToThreeObj.
1 parent 4afd438 commit ac691c0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

js/src/_base/Three.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,16 @@ var ThreeModel = widgets.WidgetModel.extend({
343343

344344
syncAllProps = syncAllProps == null ? false : syncAllProps;
345345

346+
// Collect all the keys to set in one go
347+
var toSet = {};
348+
346349
_.each(this.property_converters, function(converterName, propName) {
347350
if (!syncAllProps && !(propName in this.props_created_by_three)) {
348351
return;
349352
}
350353

351354
if (!converterName) {
352-
this.set(propName, this.obj[propName]);
355+
toSet[propName] = this.obj[propName];
353356
return;
354357
}
355358

@@ -359,9 +362,14 @@ var ThreeModel = widgets.WidgetModel.extend({
359362
throw new Error('invalid converter name: ' + converterName);
360363
}
361364

362-
this.set(propName, converterFn.bind(this)(this.obj[propName], propName));
365+
toSet[propName] = converterFn.bind(this)(this.obj[propName], propName);
363366
}, this);
364367

368+
if (toSet) {
369+
// Apply all direct changes at once
370+
this.set(toSet, 'pushFromThree');
371+
}
372+
365373
// mappers are used for more complicated conversions between model and three props
366374
// see: DataTexture
367375
_.each(this.property_mappers, function(mapperName, dataKey) {

0 commit comments

Comments
 (0)