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
At the moment, when a function has overloads, we only render the first description — see for example svelte/events#on, where we display this...
Attaches an event handler to the window and returns a function that removes the handler. Using this rather than addEventListener will preserve the correct order relative to handlers added declaratively (with attributes like onclick), which use event delegation for performance reasons
...and disregard all the subtly different ones. The result is that the documentation is incorrect unless you're attaching listeners to window.
Another example is svelte/store#derived, where instead of this (which is gibberish in any case!)...
...it might be nice to have something like this, which although a bit repetitive is arguably more comprehensible than what we have now:
derived
This function has four overloads.
Create a Readable store whose value is derived from another store and a fn, which is called when it is first subscribed to and whenever the value of store changes thereafter as long as it has subscribers.
Create a Readable store whose value is derived from multiple stores and a fn, which is called when it is first subscribed to and whenever any of the store values change thereafter as long as it has subscribers.
Create a Readable store whose value is updated by calls to set and update arguments provided to fn, which is called when it is first subscribed to and whenever the value of store changes thereafter as long as it has subscribers.
If fn returns a function, it will be called before fn re-runs, and when there are no more subscribers, allowing you to perform cleanup work.
An optional third argument provides an initial value, if set/update are called asynchronously.
Create a Readable store whose value is updated by calls to set and update arguments provided to fn, which is called when it is first subscribed to and whenever the value of stores change thereafter as long as it has subscribers.
If fn returns a function, it will be called before fn re-runs, and when there are no more subscribers, allowing you to perform cleanup work.
An optional third argument provides an initial value, if set/update are called asynchronously.
Perhaps more importantly, having separate overloads like this would mean more appropriate inline documentation (though TS will default to the first overload, in cases where inference isn't yet possible).
Above all, this has reminded me how much I hate overloads.
The text was updated successfully, but these errors were encountered:
Perhaps to help newer devs understand, we could use another term instead of "overloads"?
I'm not exactly sure what the replacement would be, but overloads isn't a term most new devs know.
At the moment, when a function has overloads, we only render the first description — see for example svelte/events#on, where we display this...
...and disregard all the subtly different ones. The result is that the documentation is incorrect unless you're attaching listeners to
window
.Another example is
svelte/store#derived
, where instead of this (which is gibberish in any case!)......it might be nice to have something like this, which although a bit repetitive is arguably more comprehensible than what we have now:
derived
This function has four overloads.
Create a
Readable
store whose value is derived from anotherstore
and afn
, which is called when it is first subscribed to and whenever the value ofstore
changes thereafter as long as it has subscribers.Create a
Readable
store whose value is derived from multiplestores
and afn
, which is called when it is first subscribed to and whenever any of the store values change thereafter as long as it has subscribers.Create a
Readable
store whose value is updated by calls toset
andupdate
arguments provided tofn
, which is called when it is first subscribed to and whenever the value ofstore
changes thereafter as long as it has subscribers.If
fn
returns a function, it will be called beforefn
re-runs, and when there are no more subscribers, allowing you to perform cleanup work.An optional third argument provides an initial value, if
set
/update
are called asynchronously.Create a
Readable
store whose value is updated by calls toset
andupdate
arguments provided tofn
, which is called when it is first subscribed to and whenever the value ofstores
change thereafter as long as it has subscribers.If
fn
returns a function, it will be called beforefn
re-runs, and when there are no more subscribers, allowing you to perform cleanup work.An optional third argument provides an initial value, if
set
/update
are called asynchronously.Perhaps more importantly, having separate overloads like this would mean more appropriate inline documentation (though TS will default to the first overload, in cases where inference isn't yet possible).
Above all, this has reminded me how much I hate overloads.
The text was updated successfully, but these errors were encountered: