mirror of https://github.com/vuejs/core.git
Merge 00b5ef60e2
into 56be3dd4db
This commit is contained in:
commit
e53a3cd9a3
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
import {
|
import {
|
||||||
type ComponentPublicInstance,
|
type ComponentPublicInstance,
|
||||||
|
createApp,
|
||||||
defineComponent,
|
defineComponent,
|
||||||
h,
|
h,
|
||||||
nextTick,
|
nextTick,
|
||||||
|
@ -598,4 +599,45 @@ describe('component: emit', () => {
|
||||||
render(h(ComponentC), el)
|
render(h(ComponentC), el)
|
||||||
expect(renderFn).toHaveBeenCalledTimes(1)
|
expect(renderFn).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('merging emits for a component that is also used as a mixin', () => {
|
||||||
|
const render = () => h('div')
|
||||||
|
const CompA = {
|
||||||
|
render,
|
||||||
|
}
|
||||||
|
const validateByMixin = vi.fn(() => true)
|
||||||
|
const validateByGlobalMixin = vi.fn(() => true)
|
||||||
|
|
||||||
|
const mixin = {
|
||||||
|
emits: {
|
||||||
|
one: validateByMixin,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const CompB = defineComponent({
|
||||||
|
mixins: [mixin, CompA],
|
||||||
|
created(this) {
|
||||||
|
this.$emit('one', 1)
|
||||||
|
},
|
||||||
|
render,
|
||||||
|
})
|
||||||
|
|
||||||
|
const app = createApp({
|
||||||
|
render() {
|
||||||
|
return [h(CompA), h(CompB)]
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
app.mixin({
|
||||||
|
emits: {
|
||||||
|
one: validateByGlobalMixin,
|
||||||
|
two: null,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const root = nodeOps.createElement('div')
|
||||||
|
app.mount(root)
|
||||||
|
expect(validateByMixin).toHaveBeenCalledTimes(1)
|
||||||
|
expect(validateByGlobalMixin).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -228,12 +228,14 @@ export function emit(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mixinEmitsCache = new WeakMap<ConcreteComponent, ObjectEmitsOptions>()
|
||||||
export function normalizeEmitsOptions(
|
export function normalizeEmitsOptions(
|
||||||
comp: ConcreteComponent,
|
comp: ConcreteComponent,
|
||||||
appContext: AppContext,
|
appContext: AppContext,
|
||||||
asMixin = false,
|
asMixin = false,
|
||||||
): ObjectEmitsOptions | null {
|
): ObjectEmitsOptions | null {
|
||||||
const cache = appContext.emitsCache
|
const cache =
|
||||||
|
__FEATURE_OPTIONS_API__ && asMixin ? mixinEmitsCache : appContext.emitsCache
|
||||||
const cached = cache.get(comp)
|
const cached = cache.get(comp)
|
||||||
if (cached !== undefined) {
|
if (cached !== undefined) {
|
||||||
return cached
|
return cached
|
||||||
|
|
Loading…
Reference in New Issue