feat: add type of `$effect.active` (#9624)

pull/9607/head
Yuichiro Yamashita 12 months ago committed by GitHub
parent d8d9be39d3
commit c7121aa38c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
feat: add type of `$effect.active`

@ -68,6 +68,28 @@ declare namespace $effect {
* @param fn The function to execute
*/
export function pre(fn: () => void | (() => void)): void;
/**
* The `$effect.active` rune is an advanced feature that tells you whether or not the code is running inside an effect or inside your template.
*
* Example:
* ```svelte
* <script>
* console.log('in component setup:', $effect.active()); // false
*
* $effect(() => {
* console.log('in effect:', $effect.active()); // true
* });
* </script>
*
* <p>in template: {$effect.active()}</p> <!-- true -->
* ```
*
* This allows you to (for example) add things like subscriptions without causing memory leaks, by putting them in child effects.
*
* https://svelte-5-preview.vercel.app/docs/runes#$effect-active
*/
export function active(): boolean;
}
/**

Loading…
Cancel
Save