Skip to content

Commit db21bb6

Browse files
committed
Convert funcs of nullable prop types handle null
1 parent e1798b8 commit db21bb6

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

js/src/_base/Three.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,19 +499,28 @@ var ThreeModel = widgets.WidgetModel.extend({
499499
},
500500

501501
convertBoolThreeToModel: function(v) {
502+
if (v === null) {
503+
return null;
504+
}
502505
// Coerce falsy/truthy:
503506
return !!v;
504507
},
505508

506509
// Enum
507510
convertEnumModelToThree: function(e) {
511+
if (e === null) {
512+
return null;
513+
}
508514
return THREE[e];
509515
},
510516

511517
convertEnumThreeToModel: function(e, propName) {
518+
if (e === null) {
519+
return null;
520+
}
512521
var enumType = this.enum_property_types[propName];
513522
var enumValues = Enums[enumType];
514-
var enumValueName = enumValues[this.obj[propName]];
523+
var enumValueName = enumValues[e];
515524
return enumValueName;
516525
},
517526

@@ -705,6 +714,9 @@ var ThreeModel = widgets.WidgetModel.extend({
705714
},
706715

707716
convertUniformDictModelToThree: function(modelDict) {
717+
if (modelDict === null) {
718+
return null;
719+
}
708720
// Convert any strings to THREE.Color
709721
// Just modify dict in-place, as it should serialize the same
710722
Object.keys(modelDict).forEach(function(k) {
@@ -772,23 +784,35 @@ var ThreeModel = widgets.WidgetModel.extend({
772784

773785
// ArrayBuffer
774786
convertArrayBufferModelToThree: function(arr) {
787+
if (arr === null) {
788+
return null;
789+
}
775790
if (arr instanceof widgets.WidgetModel) {
776791
return arr.get('array').data;
777792
}
778793
return arr.data;
779794
},
780795

781796
convertArrayBufferThreeToModel: function(arrBuffer) {
797+
if (arrBuffer === null) {
798+
return null;
799+
}
782800
// Never back-convert to a new widget
783801
return ndarray(arrBuffer);
784802
},
785803

786804
// Color
787805
convertColorModelToThree: function(c) {
806+
if (c === null) {
807+
return null;
808+
}
788809
return new THREE.Color(c);
789810
},
790811

791812
convertColorThreeToModel: function(c) {
813+
if (c === null) {
814+
return null;
815+
}
792816
return '#' + c.getHexString();
793817
},
794818

0 commit comments

Comments
 (0)