You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You cannot emit events in Svelte Web Components with the Svelte dispatcher.
Describe the proposed solution
I think adding an option in the dispatch callback to emit from the component if it extends an HTMLElement would be a possible solution.
src/runtime/internal/lifecycle.ts
exportfunctioncreateEventDispatcher<EventMapextends{}=any>(): <EventKeyextendsExtract<keyofEventMap,string>>(type: EventKey,detail?: EventMap[EventKey],options?: DispatchOptions)=>boolean{constcomponent=get_current_component();return(type: string,detail?: any,{ cancelable =false, composed, bubbles }={}): boolean=>{constcallbacks=component.$$.callbacks[type];constisCustomElement=componentinstanceofHTMLElement;if(callbacks||isCustomElement){// TODO are there situations where events could be dispatched// in a server (non-DOM) environment?constevent=custom_event(type,detail,{ cancelable, composed, bubbles });callbacks.slice().forEach((fn)=>{fn.call(component,event);});// dispatch from el if Custom Elementif(isCustomElement){component.dispatchEvent(event);}return!event.defaultPrevented;}returntrue;};}
Alternatives considered
The workaround I use in my components is as follows.
Describe the problem
You cannot emit events in Svelte Web Components with the Svelte dispatcher.
Describe the proposed solution
I think adding an option in the dispatch callback to emit from the component if it extends an HTMLElement would be a possible solution.
src/runtime/internal/lifecycle.ts
Alternatives considered
The workaround I use in my components is as follows.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: