Skip to content

Commit c7121aa

Browse files
authored
feat: add type of $effect.active (#9624)
1 parent d8d9be3 commit c7121aa

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

.changeset/dirty-garlics-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
feat: add type of `$effect.active`

packages/svelte/src/main/ambient.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ declare namespace $effect {
6868
* @param fn The function to execute
6969
*/
7070
export function pre(fn: () => void | (() => void)): void;
71+
72+
/**
73+
* 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.
74+
*
75+
* Example:
76+
* ```svelte
77+
* <script>
78+
* console.log('in component setup:', $effect.active()); // false
79+
*
80+
* $effect(() => {
81+
* console.log('in effect:', $effect.active()); // true
82+
* });
83+
* </script>
84+
*
85+
* <p>in template: {$effect.active()}</p> <!-- true -->
86+
* ```
87+
*
88+
* This allows you to (for example) add things like subscriptions without causing memory leaks, by putting them in child effects.
89+
*
90+
* https://svelte-5-preview.vercel.app/docs/runes#$effect-active
91+
*/
92+
export function active(): boolean;
7193
}
7294

7395
/**

0 commit comments

Comments
 (0)