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
The change in svelte's source seems small in scale:
functioncustom_event(type,detail,opts){// changed to add "opts"conste=document.createEvent('CustomEvent');e.initCustomEvent(type,false,!opts ? false : opts.cancelable===true,detail);// changedreturne;}functioncreateEventDispatcher(opts){// changed to add "opts"constcomponent=get_current_component();return(type,detail)=>{constcallbacks=component.$$.callbacks[type];if(callbacks){// TODO are there situations where events could be dispatched// in a server (non-DOM) environment?constevent=custom_event(type,detail,opts);// changedcallbacks.slice().forEach(fn=>{fn.call(component,event);});returnevent;// added}};}
Alternatives considered
The alternative for the Tabs component are:
to delegate the value switching to the parent component: Tabs only sends an event with the new value, it's up to the parent to change the prop passed to value.
use callbacks instead of events: a callback with a return value could be passed as a prop, and if the return value is false, the prop is not changed
adding an extra prop shouldChangeValue, and other ugly solutions
Importance
would make my life easier
The text was updated successfully, but these errors were encountered:
Describe the problem
Similar to DOM events, I want to be able to cancel dispatched event.
An example is a
Tabs
component:This works well. The user can click a tab to switch tabs. But I may want to prevent that behavior:
Describe the proposed solution
It would be nice to be able to do:
And that the
Tabs
component can detect if the event was prevented:The change in svelte's source seems small in scale:
Alternatives considered
The alternative for the
Tabs
component are:Tabs
only sends an event with the new value, it's up to the parent to change the prop passed tovalue
.false
, the prop is not changedshouldChangeValue
, and other ugly solutionsImportance
would make my life easier
The text was updated successfully, but these errors were encountered: