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
If a function is passed as the second argument, it will be called when the number of subscribers goes from zero to one (but not from one to two, etc). That function will be passed a `set` function which changes the value of the store. It must return a `stop` function that is called when the subscriber count goes from one to zero.
298
+
If a function is passed as the second argument, it will be called when the number of subscribers goes from zero to one (but not from one to two, etc). That function will be passed a `set` function which changes the value of the store, and optionally an `update` function which works like the `update` method on the store, taking a callback to calculate the store's new value from its old value. It must return a `stop` function that is called when the subscriber count goes from one to zero.
299
299
300
300
```js
301
301
import { writable } from'svelte/store';
@@ -338,6 +338,16 @@ const time = readable(null, set => {
338
338
339
339
return () =>clearInterval(interval);
340
340
});
341
+
342
+
constticktock=readable(null, (set, update) => {
343
+
set('tick');
344
+
345
+
constinterval=setInterval(() => {
346
+
update(sound=> sound ==='tick'?'tock':'tick');
347
+
}, 1000);
348
+
349
+
return () =>clearInterval(interval);
350
+
});
341
351
```
342
352
343
353
#### `derived`
@@ -346,13 +356,13 @@ const time = readable(null, set => {
The callback can set a value asynchronously by accepting a second argument, `set`, and calling it when appropriate.
382
+
The callback can set a value asynchronously by accepting a second argument, `set`, and an optional third argument, `update`, calling either or both of them when appropriate.
373
383
374
-
In this case, you can also pass a third argument to `derived` — the initial value of the derived store before `set` is first called.
384
+
In this case, you can also pass a third argument to `derived` — the initial value of the derived store before `set`or `update`is first called. If no initial value is specified, the store's initial value will be `undefined`.
*`easing` (`function`, default `cubicOut`) — an [easing function](docs#svelte_easing)
811
-
*`fallback` (`function`) — A fallback [transition](docs#transition_fn) to use for send when there is no matching element being received, and for receive when there is no element being sent.
828
+
*`fallback` (`function`) — A fallback [transition](docs#transition_fn) to use for send when there is no matching element being received, and for receive when there is no element being sent.
0 commit comments