File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 3
3
4
4
import {
5
5
type ComponentPublicInstance ,
6
+ createApp ,
6
7
defineComponent ,
7
8
h ,
8
9
nextTick ,
@@ -598,4 +599,45 @@ describe('component: emit', () => {
598
599
render ( h ( ComponentC ) , el )
599
600
expect ( renderFn ) . toHaveBeenCalledTimes ( 1 )
600
601
} )
602
+
603
+ test ( 'merging emits for a component that is also used as a mixin' , ( ) => {
604
+ const render = ( ) => h ( 'div' )
605
+ const CompA = {
606
+ render,
607
+ }
608
+ const validateByMixin = vi . fn ( ( ) => true )
609
+ const validateByGlobalMixin = vi . fn ( ( ) => true )
610
+
611
+ const mixin = {
612
+ emits : {
613
+ one : validateByMixin ,
614
+ } ,
615
+ }
616
+
617
+ const CompB = defineComponent ( {
618
+ mixins : [ mixin , CompA ] ,
619
+ created ( this ) {
620
+ this . $emit ( 'one' , 1 )
621
+ } ,
622
+ render,
623
+ } )
624
+
625
+ const app = createApp ( {
626
+ render ( ) {
627
+ return [ h ( CompA ) , h ( CompB ) ]
628
+ } ,
629
+ } )
630
+
631
+ app . mixin ( {
632
+ emits : {
633
+ one : validateByGlobalMixin ,
634
+ two : null ,
635
+ } ,
636
+ } )
637
+
638
+ const root = nodeOps . createElement ( 'div' )
639
+ app . mount ( root )
640
+ expect ( validateByMixin ) . toHaveBeenCalledTimes ( 1 )
641
+ expect ( validateByGlobalMixin ) . not . toHaveBeenCalled ( )
642
+ } )
601
643
} )
Original file line number Diff line number Diff line change @@ -232,12 +232,14 @@ export function emit(
232
232
}
233
233
}
234
234
235
+ const mixinEmitsCache = new WeakMap < ConcreteComponent , ObjectEmitsOptions > ( )
235
236
export function normalizeEmitsOptions (
236
237
comp : ConcreteComponent ,
237
238
appContext : AppContext ,
238
239
asMixin = false ,
239
240
) : ObjectEmitsOptions | null {
240
- const cache = appContext . emitsCache
241
+ const cache =
242
+ __FEATURE_OPTIONS_API__ && asMixin ? mixinEmitsCache : appContext . emitsCache
241
243
const cached = cache . get ( comp )
242
244
if ( cached !== undefined ) {
243
245
return cached
You can’t perform that action at this time.
0 commit comments