File tree Expand file tree Collapse file tree 2 files changed +36
-6
lines changed Expand file tree Collapse file tree 2 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -223,6 +223,31 @@ describe('defineCustomElement', () => {
223
223
expect ( e . getAttribute ( 'baz-qux' ) ) . toBe ( 'four' )
224
224
} )
225
225
226
+ test ( 'props via attributes and properties changed together' , async ( ) => {
227
+ const e = new E ( )
228
+ e . foo = 'foo1'
229
+ e . bar = { x : 'bar1' }
230
+ container . appendChild ( e )
231
+ await nextTick ( )
232
+ expect ( e . shadowRoot ! . innerHTML ) . toBe ( '<div>foo1</div><div>bar1</div>' )
233
+
234
+ // change attr then property
235
+ e . setAttribute ( 'foo' , 'foo2' )
236
+ e . bar = { x : 'bar2' }
237
+ await nextTick ( )
238
+ expect ( e . shadowRoot ! . innerHTML ) . toBe ( '<div>foo2</div><div>bar2</div>' )
239
+ expect ( e . getAttribute ( 'foo' ) ) . toBe ( 'foo2' )
240
+ expect ( e . hasAttribute ( 'bar' ) ) . toBe ( false )
241
+
242
+ // change prop then attr
243
+ e . bar = { x : 'bar3' }
244
+ e . setAttribute ( 'foo' , 'foo3' )
245
+ await nextTick ( )
246
+ expect ( e . shadowRoot ! . innerHTML ) . toBe ( '<div>foo3</div><div>bar3</div>' )
247
+ expect ( e . getAttribute ( 'foo' ) ) . toBe ( 'foo3' )
248
+ expect ( e . hasAttribute ( 'bar' ) ) . toBe ( false )
249
+ } )
250
+
226
251
test ( 'props via hyphen property' , async ( ) => {
227
252
const Comp = defineCustomElement ( {
228
253
props : {
Original file line number Diff line number Diff line change @@ -346,6 +346,12 @@ export class VueElement
346
346
} )
347
347
}
348
348
349
+ private _processMutations ( mutations : MutationRecord [ ] ) {
350
+ for ( const m of mutations ) {
351
+ this . _setAttr ( m . attributeName ! )
352
+ }
353
+ }
354
+
349
355
/**
350
356
* resolve inner component definition (handle possible async component)
351
357
*/
@@ -360,11 +366,7 @@ export class VueElement
360
366
}
361
367
362
368
// watch future attr changes
363
- this . _ob = new MutationObserver ( mutations => {
364
- for ( const m of mutations ) {
365
- this . _setAttr ( m . attributeName ! )
366
- }
367
- } )
369
+ this . _ob = new MutationObserver ( this . _processMutations . bind ( this ) )
368
370
369
371
this . _ob . observe ( this , { attributes : true } )
370
372
@@ -514,7 +516,10 @@ export class VueElement
514
516
// reflect
515
517
if ( shouldReflect ) {
516
518
const ob = this . _ob
517
- ob && ob . disconnect ( )
519
+ if ( ob ) {
520
+ this . _processMutations ( ob . takeRecords ( ) )
521
+ ob . disconnect ( )
522
+ }
518
523
if ( val === true ) {
519
524
this . setAttribute ( hyphenate ( key ) , '' )
520
525
} else if ( typeof val === 'string' || typeof val === 'number' ) {
You can’t perform that action at this time.
0 commit comments