fix: bubble alias

pull/8356/head
Fred Martini 4 years ago
parent 719f3a6b20
commit 617b9116ba

@ -147,7 +147,7 @@ export function hasContext(key): boolean {
} }
function start_bubble(type: string, bubble: Bubble, callback: Callback) { 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) { if (dispose) {
bubble.r.set(callback, 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 { 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) => { if (type === '*') {
let typeToListen: string; return add_bubble(component, type, (callback, options, eventType) => {
if (type === '*') { let typeToListen: string = null;
if (typeName === '*') { if (typeName === '*') {
typeToListen = eventType; typeToListen = eventType;
} else if (typeName.startsWith('*')) { } else if (typeName.startsWith('*')) {
@ -221,12 +221,13 @@ export function bubble(component: SvelteComponent, listen_func: Function, node:
typeToListen = eventType.substring(len-1); typeToListen = eventType.substring(len-1);
} }
} }
} else if (eventType === typeName) { if (typeToListen) {
typeToListen = type; 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);
}); });
} }

@ -25,7 +25,7 @@ export interface Callback {
o?: boolean | AddEventListenerOptions | EventListenerOptions; 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 { export interface Bubble {
f: CallbackFactory; f: CallbackFactory;

Loading…
Cancel
Save