mirror of
https://github.com/youzan/vant.git
synced 2025-12-22 01:07:29 +08:00
[bugfix] functional component multi listeners (#2717)
This commit is contained in:
@@ -20,7 +20,8 @@ const inheritKey = [
|
||||
|
||||
const mapInheritKey: ObjectIndex = { nativeOn: 'on' };
|
||||
|
||||
export function inheritContext(context: Context): InheritContext {
|
||||
// inherit partial context, map nativeOn to on
|
||||
export function inherit(context: Context): InheritContext {
|
||||
return inheritKey.reduce(
|
||||
(obj, key) => {
|
||||
if (context.data[key]) {
|
||||
@@ -31,3 +32,17 @@ export function inheritContext(context: Context): InheritContext {
|
||||
{} as InheritContext
|
||||
);
|
||||
}
|
||||
|
||||
// emit event
|
||||
export function emit(context: Context, eventName: string, ...args: any[]) {
|
||||
const listeners = context.listeners[eventName];
|
||||
if (listeners) {
|
||||
if (Array.isArray(listeners)) {
|
||||
listeners.forEach(listener => {
|
||||
listener(...args);
|
||||
})
|
||||
} else {
|
||||
listeners(...args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user