@@ -154,6 +154,7 @@ export class VueElement extends BaseClass {
154
154
155
155
private _connected = false
156
156
private _resolved = false
157
+ private _numberProps : Record < string , true > | null = null
157
158
private _styles ?: HTMLStyleElement [ ]
158
159
159
160
constructor (
@@ -179,19 +180,18 @@ export class VueElement extends BaseClass {
179
180
this . _setAttr ( this . attributes [ i ] . name )
180
181
}
181
182
// watch future attr changes
182
- const observer = new MutationObserver ( mutations => {
183
+ new MutationObserver ( mutations => {
183
184
for ( const m of mutations ) {
184
185
this . _setAttr ( m . attributeName ! )
185
186
}
186
- } )
187
- observer . observe ( this , { attributes : true } )
187
+ } ) . observe ( this , { attributes : true } )
188
188
}
189
189
190
190
connectedCallback ( ) {
191
191
this . _connected = true
192
192
if ( ! this . _instance ) {
193
193
this . _resolveDef ( )
194
- render ( this . _createVNode ( ) , this . shadowRoot ! )
194
+ this . _update ( )
195
195
}
196
196
}
197
197
@@ -215,15 +215,33 @@ export class VueElement extends BaseClass {
215
215
216
216
const resolve = ( def : InnerComponentDef ) => {
217
217
this . _resolved = true
218
+ const { props, styles } = def
219
+ const hasOptions = ! isArray ( props )
220
+ const rawKeys = props ? ( hasOptions ? Object . keys ( props ) : props ) : [ ]
221
+
222
+ // cast Number-type props set before resolve
223
+ let numberProps
224
+ if ( hasOptions ) {
225
+ for ( const key in this . _props ) {
226
+ const opt = props [ key ]
227
+ if ( opt === Number || ( opt && opt . type === Number ) ) {
228
+ this . _props [ key ] = toNumber ( this . _props [ key ] )
229
+ ; ( numberProps || ( numberProps = Object . create ( null ) ) ) [ key ] = true
230
+ }
231
+ }
232
+ }
233
+ if ( numberProps ) {
234
+ this . _numberProps = numberProps
235
+ this . _update ( )
236
+ }
237
+
218
238
// check if there are props set pre-upgrade or connect
219
239
for ( const key of Object . keys ( this ) ) {
220
240
if ( key [ 0 ] !== '_' ) {
221
241
this . _setProp ( key , this [ key as keyof this] )
222
242
}
223
243
}
224
- const { props, styles } = def
225
244
// defining getter/setters on prototype
226
- const rawKeys = props ? ( isArray ( props ) ? props : Object . keys ( props ) ) : [ ]
227
245
for ( const key of rawKeys . map ( camelize ) ) {
228
246
Object . defineProperty ( this , key , {
229
247
get ( ) {
@@ -246,7 +264,11 @@ export class VueElement extends BaseClass {
246
264
}
247
265
248
266
protected _setAttr ( key : string ) {
249
- this . _setProp ( camelize ( key ) , toNumber ( this . getAttribute ( key ) ) , false )
267
+ let value = this . getAttribute ( key )
268
+ if ( this . _numberProps && this . _numberProps [ key ] ) {
269
+ value = toNumber ( value )
270
+ }
271
+ this . _setProp ( camelize ( key ) , value , false )
250
272
}
251
273
252
274
/**
@@ -263,7 +285,7 @@ export class VueElement extends BaseClass {
263
285
if ( val !== this . _props [ key ] ) {
264
286
this . _props [ key ] = val
265
287
if ( this . _instance ) {
266
- render ( this . _createVNode ( ) , this . shadowRoot ! )
288
+ this . _update ( )
267
289
}
268
290
// reflect
269
291
if ( shouldReflect ) {
@@ -278,6 +300,10 @@ export class VueElement extends BaseClass {
278
300
}
279
301
}
280
302
303
+ private _update ( ) {
304
+ render ( this . _createVNode ( ) , this . shadowRoot ! )
305
+ }
306
+
281
307
private _createVNode ( ) : VNode < any , any > {
282
308
const vnode = createVNode ( this . _def , extend ( { } , this . _props ) )
283
309
if ( ! this . _instance ) {
@@ -298,7 +324,7 @@ export class VueElement extends BaseClass {
298
324
if ( ! ( this . _def as ComponentOptions ) . __asyncLoader ) {
299
325
// reload
300
326
this . _instance = null
301
- render ( this . _createVNode ( ) , this . shadowRoot ! )
327
+ this . _update ( )
302
328
}
303
329
}
304
330
}
0 commit comments