@@ -29,6 +29,31 @@ _.extend(BaseType.prototype, {
29
29
} ,
30
30
} )
31
31
32
+ function genInstanceTraitlet ( typeName , nullable , args , kwargs ) {
33
+ var nullableStr = nullable ? 'True' : 'False' ;
34
+ // allow type unions
35
+ if ( typeName instanceof Array ) {
36
+ var instances = typeName . map ( function ( tname ) {
37
+ return ` Instance(${ tname } , allow_none=${ nullableStr } )` ;
38
+ } ) ;
39
+ return 'Union([\n' + instances . join ( ',\n' ) + '\n ]).tag(sync=True, **widget_serialization)' ;
40
+ }
41
+
42
+ if ( typeName . toLowerCase ( ) === 'this' ) {
43
+ return 'This().tag(sync=True, **widget_serialization)' ;
44
+ }
45
+
46
+ var ret = `Instance(${ typeName } ` ;
47
+ if ( args !== undefined ) {
48
+ ret += `, args=${ args } ` ;
49
+ }
50
+ if ( kwargs !== undefined ) {
51
+ ret += `, kw=${ kwargs } ` ;
52
+ }
53
+ ret += `, allow_none=${ nullableStr } ).tag(sync=True, **widget_serialization)` ;
54
+ return ret ;
55
+ }
56
+
32
57
function ThreeType ( typeName , options = { } ) {
33
58
this . typeName = typeName || '' ;
34
59
this . defaultValue = null ;
@@ -39,28 +64,16 @@ function ThreeType(typeName, options={}) {
39
64
}
40
65
_ . extend ( ThreeType . prototype , BaseType . prototype , {
41
66
getTraitlet : function ( ) {
42
- var nullableStr = this . nullable ? 'True' : 'False' ;
43
- // allow type unions
44
- if ( this . typeName instanceof Array ) {
45
- var instances = this . typeName . map ( function ( typeName ) {
46
- return ` Instance(${ typeName || 'ThreeWidget' } , allow_none=${ nullableStr } )` ;
67
+ var typeName = this . typeName ;
68
+ if ( typeName instanceof Array ) {
69
+ typeName = _ . each ( typeName , function ( tname ) {
70
+ return `${ tname || 'ThreeWidget' } ` ;
47
71
} ) ;
48
- return 'Union([\n' + instances . join ( ',\n' ) + '\n ]).tag(sync=True, **widget_serialization)' ;
49
- }
50
-
51
- if ( this . typeName . toLowerCase ( ) === 'this' ) {
52
- return 'This().tag(sync=True, **widget_serialization)' ;
53
- }
54
-
55
- var ret = `Instance(${ this . typeName || 'ThreeWidget' } ` ;
56
- if ( this . args !== undefined ) {
57
- ret += `, args=${ this . args } ` ;
58
- }
59
- if ( this . kwargs !== undefined ) {
60
- ret += `, kw=${ this . kwargs } ` ;
72
+ } else {
73
+ typeName = `${ typeName || 'ThreeWidget' } ` ;
61
74
}
62
- ret += `, allow_none= ${ nullableStr } ).tag(sync=True, **widget_serialization)` ;
63
- return ret ;
75
+ return genInstanceTraitlet (
76
+ typeName , this . nullable , this . args , this . kwargs ) ;
64
77
} ,
65
78
getPropArrayName : function ( ) {
66
79
return 'three_properties' ;
@@ -79,28 +92,8 @@ _.extend(ForwardDeclaredThreeType.prototype, ThreeType.prototype, {
79
92
return this . modulePath + '.' + this . typeName ;
80
93
} ,
81
94
getTraitlet : function ( ) {
82
- var nullableStr = this . nullable ? 'True' : 'False' ;
83
- // allow type unions
84
- if ( this . typeName instanceof Array ) {
85
- var instances = this . typeName . map ( function ( typeName ) {
86
- return ` Instance('${ this . forwardType ( ) } ', allow_none=${ nullableStr } )` ;
87
- } ) ;
88
- return 'Union([\n' + instances . join ( ',\n' ) + '\n ]).tag(sync=True, **widget_serialization)' ;
89
- }
90
-
91
- if ( this . typeName . toLowerCase ( ) === 'this' ) {
92
- return 'This().tag(sync=True, **widget_serialization)' ;
93
- }
94
-
95
- var ret = `Instance('${ this . forwardType ( ) } '` ;
96
- if ( this . args !== undefined ) {
97
- ret += `, args=${ this . args } ` ;
98
- }
99
- if ( this . kwargs !== undefined ) {
100
- ret += `, kw=${ this . kwargs } ` ;
101
- }
102
- ret += `, allow_none=${ nullableStr } ).tag(sync=True, **widget_serialization)` ;
103
- return ret ;
95
+ return genInstanceTraitlet (
96
+ this . forwardType ( ) , this . nullable , this . args , this . kwargs ) ;
104
97
} ,
105
98
} ) ;
106
99
0 commit comments