|
|
|
@ -6,8 +6,7 @@ export function set_current_component(component) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/** @returns {any} */
|
|
|
|
/** @returns {any} */
|
|
|
|
export function get_current_component() {
|
|
|
|
export function get_current_component() {
|
|
|
|
if (!current_component)
|
|
|
|
if (!current_component) throw new Error('Function called outside component initialization');
|
|
|
|
throw new Error('Function called outside component initialization');
|
|
|
|
|
|
|
|
return current_component;
|
|
|
|
return current_component;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -87,7 +86,7 @@ export function onDestroy(fn) {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export function createEventDispatcher() {
|
|
|
|
export function createEventDispatcher() {
|
|
|
|
const component = get_current_component();
|
|
|
|
const component = get_current_component();
|
|
|
|
return ((type, detail, { cancelable = false } = {}) => {
|
|
|
|
return (type, detail, { cancelable = false } = {}) => {
|
|
|
|
const callbacks = component.$$.callbacks[type];
|
|
|
|
const callbacks = component.$$.callbacks[type];
|
|
|
|
if (callbacks) {
|
|
|
|
if (callbacks) {
|
|
|
|
// TODO are there situations where events could be dispatched
|
|
|
|
// TODO are there situations where events could be dispatched
|
|
|
|
@ -99,7 +98,7 @@ export function createEventDispatcher() {
|
|
|
|
return !event.defaultPrevented;
|
|
|
|
return !event.defaultPrevented;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Associates an arbitrary `context` object with the current component and the specified `key`
|
|
|
|
* Associates an arbitrary `context` object with the current component and the specified `key`
|
|
|
|
@ -159,9 +158,6 @@ export function bubble(component, event) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @typedef {Object} EventDispatcher */
|
|
|
|
/** @typedef {Object} EventDispatcher */
|
|
|
|
/** @typedef {Object} DispatchOptions
|
|
|
|
/** @typedef {Object} DispatchOptions
|
|
|
|
* @property {boolean} [cancelable]
|
|
|
|
* @property {boolean} [cancelable]
|
|
|
|
|