0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

Update 03-run-time.md

This commit is contained in:
Rich Harris 2019-06-25 19:38:32 -04:00 committed by GitHub
parent 5515bb49c9
commit 9806d18bdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -359,17 +359,21 @@ 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:
---
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);
const interval = setInterval(() => {
set(Date.now());
}, 1000 / $frequency);
return () => {
clearInterval(interval);
}
};
}, 'one moment...');
```