|
|
|
@ -27,9 +27,7 @@ export function onDestroy(fn: () => any) {
|
|
|
|
get_current_component().$$.on_destroy.push(fn);
|
|
|
|
get_current_component().$$.on_destroy.push(fn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function createEventDispatcher<
|
|
|
|
export function createEventDispatcher<EventMap extends {} = any>(): <EventKey extends Extract<keyof EventMap, string>>(type: EventKey, detail?: EventMap[EventKey]) => void {
|
|
|
|
EventMap extends {} = any
|
|
|
|
|
|
|
|
>(): <EventKey extends Extract<keyof EventMap, string>>(type: EventKey, detail?: EventMap[EventKey]) => void {
|
|
|
|
|
|
|
|
const component = get_current_component();
|
|
|
|
const component = get_current_component();
|
|
|
|
|
|
|
|
|
|
|
|
return (type: string, detail?: any) => {
|
|
|
|
return (type: string, detail?: any) => {
|
|
|
|
@ -51,7 +49,8 @@ export function createEventDispatcher<
|
|
|
|
// in a server (non-DOM) environment?
|
|
|
|
// in a server (non-DOM) environment?
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const event = custom_event(type, detail);
|
|
|
|
const event = custom_event(type, detail);
|
|
|
|
eventBinding[0].call(component, event, eventBinding[1].data);
|
|
|
|
const data = eventBinding[1] && Object.prototype.hasOwnProperty.call(eventBinding[1], 'data') ? eventBinding[1].data : {};
|
|
|
|
|
|
|
|
eventBinding[0].call(component, event, data);
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(`A component was instantiated with invalid event:bindings - ${e}`);
|
|
|
|
console.warn(`A component was instantiated with invalid event:bindings - ${e}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -61,7 +60,8 @@ export function createEventDispatcher<
|
|
|
|
// in a server (non-DOM) environment?
|
|
|
|
// in a server (non-DOM) environment?
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const event = custom_event(type, detail);
|
|
|
|
const event = custom_event(type, detail);
|
|
|
|
catchAll[0].call(component, event, catchAll[1].data);
|
|
|
|
const data = catchAll[1] && Object.prototype.hasOwnProperty.call(catchAll[1], 'data') ? catchAll[1].data : {};
|
|
|
|
|
|
|
|
catchAll[0].call(component, event, data);
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(`A component was instantiated with invalid event:bindings - ${e}`);
|
|
|
|
console.warn(`A component was instantiated with invalid event:bindings - ${e}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -71,7 +71,8 @@ export function createEventDispatcher<
|
|
|
|
// in a server (non-DOM) environment?
|
|
|
|
// in a server (non-DOM) environment?
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const event = custom_event(type, detail);
|
|
|
|
const event = custom_event(type, detail);
|
|
|
|
catchAllBinding[0].call(component, event, catchAllBinding[1].data);
|
|
|
|
const data = catchAllBinding[1] && Object.prototype.hasOwnProperty.call(catchAllBinding[1], 'data') ? catchAllBinding[1].data : {};
|
|
|
|
|
|
|
|
catchAllBinding[0].call(component, event, data);
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(`A component was instantiated with invalid on:* configuration - ${e}`);
|
|
|
|
console.warn(`A component was instantiated with invalid on:* configuration - ${e}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -95,14 +96,9 @@ export function hasContext(key): boolean {
|
|
|
|
return get_current_component().$$.context.has(key);
|
|
|
|
return get_current_component().$$.context.has(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO figure out if we still want to support
|
|
|
|
// TODO figure out if we still want to support - yes we do :)
|
|
|
|
// shorthand events, or if we want to implement
|
|
|
|
// shorthand events, or if we want to implement
|
|
|
|
// a real bubbling mechanism
|
|
|
|
// a real bubbling mechanism
|
|
|
|
export function bubble(component, event) {
|
|
|
|
export function bubble(component, event) {
|
|
|
|
const callbacks = component.$$.callbacks[event.type];
|
|
|
|
component.$$.ctx[0]['event:bindings'][event.type][0](component.$$.ctx[0]['event:bindings'][event.type][1]);
|
|
|
|
|
|
|
|
|
|
|
|
if (callbacks) {
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
callbacks.slice().forEach(fn => fn.call(this, event));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|