document changes to derived

pull/2730/head
Rich Harris 5 years ago
parent fdc51de090
commit ca1dc4cdb7

@ -324,13 +324,13 @@ const time = readable(new Date(), set => {
store = derived(a, callback: (a: any) => any)
```
```js
store = derived(a, callback: (a: any, set: (value: any) => void) => void, initial_value: any)
store = derived(a, callback: (a: any, set: (value: any) => void) => void | () => void, initial_value: any)
```
```js
store = derived([a, ...b], callback: ([a: any, ...b: any[]]) => any)
```
```js
store = derived([a, ...b], callback: ([a: any, ...b: any[]], set: (value: any) => void) => void, initial_value: any)
store = derived([a, ...b], callback: ([a: any, ...b: any[]], set: (value: any) => void) => void | () => void, initial_value: any)
```
---
@ -359,6 +359,20 @@ const delayed = derived(a, ($a, set) => {
}, 'one moment...');
```
If you return a function from the callback, it will be called when a) the callback runs again, or b) the last subscriber unsubscribes:
```js
import { derived } from 'svelte/store';
const tick = derived(frequency, ($frequency, set) => {
const interval = setInterval(() => set(Date.now()), 1000 / frequency);
return () => {
clearInterval(interval);
}
}, 'one moment...');
```
---
In both cases, an array of arguments can be passed as the first argument instead of a single store.

Loading…
Cancel
Save