From 617b9116ba2a8c1c3a5884c96d7fcc40784bf118 Mon Sep 17 00:00:00 2001 From: Fred Martini Date: Fri, 3 Mar 2023 10:30:09 +0100 Subject: [PATCH] fix: bubble alias --- src/runtime/internal/lifecycle.ts | 21 +++++++++++---------- src/runtime/internal/types.ts | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/runtime/internal/lifecycle.ts b/src/runtime/internal/lifecycle.ts index 2e381e6692..b5a29688a7 100644 --- a/src/runtime/internal/lifecycle.ts +++ b/src/runtime/internal/lifecycle.ts @@ -147,7 +147,7 @@ export function hasContext(key): boolean { } function start_bubble(type: string, bubble: Bubble, callback: Callback) { - const dispose = bubble.f(type, callback.f, callback.o); + const dispose = bubble.f(callback.f, callback.o, type); if (dispose) { bubble.r.set(callback, dispose); } @@ -205,9 +205,9 @@ export function onEventListener(type: string, fn: CallbackFactory) { export function bubble(component: SvelteComponent, listen_func: Function, node: EventTarget|SvelteComponent, type: string, typeName: string = type): Function { - return add_bubble(component, type, (eventType, callback, options) => { - let typeToListen: string; - if (type === '*') { + if (type === '*') { + return add_bubble(component, type, (callback, options, eventType) => { + let typeToListen: string = null; if (typeName === '*') { typeToListen = eventType; } else if (typeName.startsWith('*')) { @@ -221,12 +221,13 @@ export function bubble(component: SvelteComponent, listen_func: Function, node: typeToListen = eventType.substring(len-1); } } - } else if (eventType === typeName) { - typeToListen = type; - } - if (typeToListen) { - return listen_func(node, typeToListen, callback, options); - } + if (typeToListen) { + return listen_func(node, typeToListen, callback, options); + } + }); + } + return add_bubble(component, typeName, (callback, options) => { + return listen_func(node, type, callback, options); }); } diff --git a/src/runtime/internal/types.ts b/src/runtime/internal/types.ts index a957730ca3..4da02d1bf3 100644 --- a/src/runtime/internal/types.ts +++ b/src/runtime/internal/types.ts @@ -25,7 +25,7 @@ export interface Callback { o?: boolean | AddEventListenerOptions | EventListenerOptions; } -export type CallbackFactory = (type: string, callback: EventListener, options: boolean | AddEventListenerOptions | EventListenerOptions | undefined) => Function|void; +export type CallbackFactory = (callback: EventListener, options: boolean | AddEventListenerOptions | EventListenerOptions | undefined, type: string) => Function|void; export interface Bubble { f: CallbackFactory;