From the docs:
Component events created with createEventDispatcher create a CustomEvent. These events do not bubble and are not cancellable with event.preventDefault().
I understand why they couldn't bubble, but is there any reason why cancelable event aren't allowed ? It would only require adding one line in createEventDispatcher declaration (from /src/runtime/internal/lifecycle.ts)
export function createEventDispatcher() {
const component = get_current_component();
return (type: string, detail?: any): boolean => {
const callbacks = component.$$.callbacks[type];
if (callbacks) {
const event = custom_event(type, detail);
callbacks.slice().forEach(fn => {
fn.call(component, event);
});
// Just add this line
return !event.defaultPrevented
}
};
}
and a slightly different signature for custom_event (from /src/runtime/internal/dom.ts)
export function custom_event<T=any>(type: string, detail?: T, cancelable?: boolean){}
// or anything else
From the docs:
I understand why they couldn't bubble, but is there any reason why cancelable event aren't allowed ? It would only require adding one line in
createEventDispatcherdeclaration (from /src/runtime/internal/lifecycle.ts)export function createEventDispatcher() { const component = get_current_component(); return (type: string, detail?: any): boolean => { const callbacks = component.$$.callbacks[type]; if (callbacks) { const event = custom_event(type, detail); callbacks.slice().forEach(fn => { fn.call(component, event); }); // Just add this line return !event.defaultPrevented } }; }and a slightly different signature for
custom_event(from /src/runtime/internal/dom.ts)