File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
packages/svelte/src/reactivity Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -6,10 +6,13 @@ import { DEV } from 'esm-env';
6
6
import { queue_micro_task } from '../internal/client/dom/task.js' ;
7
7
8
8
/**
9
- * Returns a `subscribe` function that, if called in an effect (including expressions in the template),
10
- * calls its `start` callback with an `update` function. Whenever `update` is called, the effect re-runs .
9
+ * Returns a `subscribe` function that integrates external event-based systems with Svelte's reactivity.
10
+ * It's particularly useful for integrating with web APIs like `MediaQuery`, `IntersectionObserver`, or `WebSocket` .
11
11
*
12
- * If `start` returns a function, it will be called when the effect is destroyed.
12
+ * If `subscribe` is called inside an effect (including indirectly, for example inside a getter),
13
+ * the `start` callback will be called with an `update` function. Whenever `update` is called, the effect re-runs.
14
+ *
15
+ * If `start` returns a cleanup function, it will be called when the effect is destroyed.
13
16
*
14
17
* If `subscribe` is called in multiple effects, `start` will only be called once as long as the effects
15
18
* are active, and the returned teardown function will only be called when all effects are destroyed.
@@ -37,6 +40,7 @@ import { queue_micro_task } from '../internal/client/dom/task.js';
37
40
* }
38
41
*
39
42
* get current() {
43
+ * // This makes the getter reactive, if read in an effect
40
44
* this.#subscribe();
41
45
*
42
46
* // Return the current state of the query, whether or not we're in an effect
You can’t perform that action at this time.
0 commit comments