Skip to content

Commit 662cfcf

Browse files
committed
Add nullable attribute for gen types + fix Unions
1 parent 410014b commit 662cfcf

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

js/scripts/prop-types.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,31 @@ _.extend(BaseType.prototype, {
2222
},
2323
})
2424

25-
function ThreeType(typeName) {
25+
function ThreeType(typeName, nullable=true) {
2626
this.typeName = typeName;
2727
this.defaultValue = null;
2828
this.serialize = true;
29+
this.nullable = nullable;
2930
}
3031
_.extend(ThreeType.prototype, BaseType.prototype, {
3132
getTraitlet: function() {
33+
var nullableStr = this.nullable ? 'True' : 'False';
3234
// allow type unions
3335
if (this.typeName instanceof Array) {
3436
// TODO: only instan
3537
var instances = this.typeName.map(function(typeName) {
36-
return ' Instance(' + typeName + ', allow_none=True).tag(sync=True, **widget_serialization)';
38+
return ' Instance(' + typeName + ', allow_none=' + nullableStr +')';
3739
});
38-
return 'Union([\n' + instances.join(',\n') + '\n ])';
40+
return 'Union([\n' + instances.join(',\n') + '\n ]).tag(sync=True, **widget_serialization)';
3941

4042
// return 'Any()';
4143
}
4244

4345
if (this.typeName.toLowerCase() === 'this') {
4446
return 'This().tag(sync=True, **widget_serialization)';
4547
}
46-
47-
return 'Instance(' + this.typeName + ', allow_none=True).tag(sync=True, **widget_serialization)';
48+
49+
return 'Instance(' + this.typeName + ', allow_none=' + nullableStr +').tag(sync=True, **widget_serialization)';
4850
},
4951
getPropArrayName: function() {
5052
return 'three_properties';

js/scripts/three-class-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,8 @@ module.exports = {
783783
superClass: 'Object3D',
784784
constructorArgs: [ 'geometry', 'material' ],
785785
properties: {
786-
material: new Types.ThreeType('Material'),
787-
geometry: new Types.ThreeType(['Geometry', 'BufferGeometry']),
786+
material: new Types.ThreeType('Material', false),
787+
geometry: new Types.ThreeType(['Geometry', 'BufferGeometry'], false),
788788
}
789789
},
790790
Points: {

0 commit comments

Comments
 (0)