Skip to content

Commit d7a6571

Browse files
committed
Use template strings in types
1 parent 6b0702e commit d7a6571

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

js/scripts/prop-types.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ _.extend(ThreeType.prototype, BaseType.prototype, {
4141
// allow type unions
4242
if (this.typeName instanceof Array) {
4343
var instances = this.typeName.map(function(typeName) {
44-
return ' Instance(' + typeName + ', allow_none=' + nullableStr +')';
44+
return ` Instance(${typeName}, allow_none=${nullableStr})`;
4545
});
4646
return 'Union([\n' + instances.join(',\n') + '\n ]).tag(sync=True, **widget_serialization)';
4747
}
@@ -50,14 +50,14 @@ _.extend(ThreeType.prototype, BaseType.prototype, {
5050
return 'This().tag(sync=True, **widget_serialization)';
5151
}
5252

53-
var ret = 'Instance(' + this.typeName;
53+
var ret = `Instance(${this.typeName}`;
5454
if (this.args !== undefined) {
55-
ret += ', args=' + this.args;
55+
ret += `, args=${this.args}`;
5656
}
5757
if (this.kwargs !== undefined) {
58-
ret += ', kw=' + this.kwargs;
58+
ret += `, kw=${this.kwargs}`;
5959
}
60-
ret += ', allow_none=' + nullableStr +').tag(sync=True, **widget_serialization)';
60+
ret += `, allow_none=${nullableStr}).tag(sync=True, **widget_serialization)`;
6161
return ret;
6262
},
6363
getPropArrayName: function() {
@@ -81,7 +81,7 @@ _.extend(ForwardDeclaredThreeType.prototype, ThreeType.prototype, {
8181
// allow type unions
8282
if (this.typeName instanceof Array) {
8383
var instances = this.typeName.map(function(typeName) {
84-
return ' Instance(\'' + this.forwardType() + '\', allow_none=' + nullableStr +')';
84+
return ` Instance('${this.forwardType()}', allow_none=${nullableStr})`;
8585
});
8686
return 'Union([\n' + instances.join(',\n') + '\n ]).tag(sync=True, **widget_serialization)';
8787
}
@@ -90,14 +90,14 @@ _.extend(ForwardDeclaredThreeType.prototype, ThreeType.prototype, {
9090
return 'This().tag(sync=True, **widget_serialization)';
9191
}
9292

93-
var ret = 'Instance(\'' + this.forwardType() + '\'';
93+
var ret = `Instance('${this.forwardType()}'`;
9494
if (this.args !== undefined) {
95-
ret += ', args=' + this.args;
95+
ret += `, args=${this.args}`;
9696
}
9797
if (this.kwargs !== undefined) {
98-
ret += ', kw=' + this.kwargs;
98+
ret += `, kw=${this.kwargs}`;
9999
}
100-
ret += ', allow_none=' + nullableStr +').tag(sync=True, **widget_serialization)';
100+
ret += `, allow_none=${nullableStr}).tag(sync=True, **widget_serialization)`;
101101
return ret;
102102
},
103103
});
@@ -143,7 +143,7 @@ _.extend(ThreeTypeDict.prototype, BaseType.prototype, {
143143
if (this.typeName === 'this') {
144144
return 'Dict(This()).tag(sync=True, **widget_serialization)';
145145
}
146-
return 'Dict(Instance(' + this.typeName + ')).tag(sync=True, **widget_serialization)';
146+
return `Dict(Instance(${this.typeName})).tag(sync=True, **widget_serialization)`;
147147
},
148148
getPropArrayName: function() {
149149
return 'three_dict_properties';
@@ -159,32 +159,31 @@ function Bool(defaultValue, nullable) {
159159
}
160160
_.extend(Bool.prototype, BaseType.prototype, {
161161
getTraitlet: function() {
162-
var pyBoolValue = this.defaultValue ? 'True' : 'False';
163162
var nullableStr = this.nullable ? 'True' : 'False';
164-
return 'Bool(' + pyBoolValue + ', allow_none=' + nullableStr + ').tag(sync=True)';
163+
return `Bool(${this.getPythonDefaultValue()}, allow_none=${nullableStr}).tag(sync=True)`;
165164
},
166165
});
167166

168167
function Int(defaultValue, nullable) {
169168
this.nullable = nullable === true;
170-
this.defaultValue = defaultValue == null && !this.nullable ? 0 : defaultValue;
169+
this.defaultValue = defaultValue === null ? !this.nullable ? 0 : 'None' : defaultValue;
171170
}
172171
_.extend(Int.prototype, BaseType.prototype, {
173172
getTraitlet: function() {
174173
var nullableStr = this.nullable ? 'True' : 'False';
175-
return 'CInt(' + this.defaultValue + ', allow_none=' + nullableStr + ').tag(sync=True)';
174+
return `CInt(${this.getPythonDefaultValue()}, allow_none=${nullableStr}).tag(sync=True)`;
176175
},
177176

178177
});
179178

180179
function Float(defaultValue, nullable) {
181180
this.nullable = nullable === true;
182-
this.defaultValue = defaultValue == null && !this.nullable ? 0.0 : defaultValue;
181+
this.defaultValue = defaultValue == null ? !this.nullable ? 0.0 : 'None' : defaultValue;
183182
}
184183
_.extend(Float.prototype, BaseType.prototype, {
185184
getTraitlet: function() {
186185
var nullableStr = this.nullable ? 'True' : 'False';
187-
return 'CFloat(' + this.getPythonDefaultValue() + ', allow_none=' + nullableStr + ').tag(sync=True)';
186+
return `CFloat(${this.getPythonDefaultValue()}, allow_none=${nullableStr}).tag(sync=True)`;
188187
},
189188
getPropertyConverterFn: function() {
190189
return 'convertFloat';
@@ -199,7 +198,7 @@ function StringType(defaultValue, nullable) {
199198
_.extend(StringType.prototype, BaseType.prototype, {
200199
getTraitlet: function() {
201200
var nullableStr = this.nullable ? 'True' : 'False';
202-
return 'Unicode(' + JSON.stringify(this.defaultValue) + ', allow_none=' + nullableStr + ').tag(sync=True)';
201+
return `Unicode(${this.getPythonDefaultValue()}, allow_none=${nullableStr}).tag(sync=True)`;
203202
},
204203

205204
});
@@ -212,7 +211,7 @@ function Enum(enumTypeName, defaultValue, nullable) {
212211
_.extend(Enum.prototype, BaseType.prototype, {
213212
getTraitlet: function() {
214213
var nullableStr = this.nullable ? 'True' : 'False';
215-
return 'Enum(' + this.enumTypeName + ', "' + this.defaultValue + ', allow_none=' + nullableStr + '").tag(sync=True)';
214+
return `Enum(${this.enumTypeName}, ${this.getPythonDefaultValue()}, allow_none=${nullableStr}).tag(sync=True)`;
216215
},
217216
getPropertyConverterFn: function() {
218217
return 'convertEnum';
@@ -224,7 +223,7 @@ function Color(defaultValue) {
224223
}
225224
_.extend(Color.prototype, BaseType.prototype, {
226225
getTraitlet: function() {
227-
return 'Unicode(' + JSON.stringify(this.defaultValue) + ').tag(sync=True)'
226+
return `Unicode(${this.getPythonDefaultValue()}).tag(sync=True)`;
228227
},
229228
getPropertyConverterFn: function() {
230229
return 'convertColor';
@@ -279,7 +278,7 @@ function DictType(defaultValue={}, nullable) {
279278
_.extend(DictType.prototype, BaseType.prototype, {
280279
getTraitlet: function() {
281280
var nullableStr = this.nullable ? 'True' : 'False';
282-
return 'Dict(default_value=' + this.defaultValue + ', allow_none=' + nullableStr + ').tag(sync=True)';
281+
return `Dict(default_value=${this.getPythonDefaultValue()}, allow_none=${nullableStr}).tag(sync=True)`;
283282
},
284283
});
285284

@@ -288,7 +287,7 @@ function FunctionType(fn) {
288287
}
289288
_.extend(FunctionType.prototype, BaseType.prototype, {
290289
getTraitlet: function() {
291-
return "Unicode('" + this.defaultValue.toString() + "').tag(sync=True)";
290+
return `Unicode('${this.defaultValue.toString()}').tag(sync=True)`;
292291
},
293292
getJSPropertyValue: function() {
294293
return this.defaultValue.toString();

0 commit comments

Comments
 (0)