pull/16398/head
Rich Harris 2 months ago
parent f45c37f2b6
commit 5df8280e9c

@ -2335,10 +2335,13 @@ declare module 'svelte/reactivity' {
constructor(query: string, fallback?: boolean | undefined); constructor(query: string, fallback?: boolean | undefined);
} }
/** /**
* Returns a `subscribe` function that, if called in an effect (including expressions in the template), * Returns a `subscribe` function that integrates external event-based systems with Svelte's reactivity.
* calls its `start` callback with an `update` function. Whenever `update` is called, the effect re-runs. * It's particularly useful for integrating with web APIs like `MediaQuery`, `IntersectionObserver`, or `WebSocket`.
* *
* If `start` returns a function, it will be called when the effect is destroyed. * If `subscribe` is called inside an effect (including indirectly, for example inside a getter),
* the `start` callback will be called with an `update` function. Whenever `update` is called, the effect re-runs.
*
* If `start` returns a cleanup function, it will be called when the effect is destroyed.
* *
* If `subscribe` is called in multiple effects, `start` will only be called once as long as the effects * If `subscribe` is called in multiple effects, `start` will only be called once as long as the effects
* are active, and the returned teardown function will only be called when all effects are destroyed. * are active, and the returned teardown function will only be called when all effects are destroyed.
@ -2366,6 +2369,7 @@ declare module 'svelte/reactivity' {
* } * }
* *
* get current() { * get current() {
* // This makes the getter reactive, if read in an effect
* this.#subscribe(); * this.#subscribe();
* *
* // Return the current state of the query, whether or not we're in an effect * // Return the current state of the query, whether or not we're in an effect

Loading…
Cancel
Save