From c7121aa38c26f5808a61767e4358ca87cfced2c4 Mon Sep 17 00:00:00 2001 From: Yuichiro Yamashita Date: Fri, 24 Nov 2023 00:03:32 +0900 Subject: [PATCH] feat: add type of `$effect.active` (#9624) --- .changeset/dirty-garlics-design.md | 5 +++++ packages/svelte/src/main/ambient.d.ts | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 .changeset/dirty-garlics-design.md diff --git a/.changeset/dirty-garlics-design.md b/.changeset/dirty-garlics-design.md new file mode 100644 index 000000000..525160b76 --- /dev/null +++ b/.changeset/dirty-garlics-design.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +feat: add type of `$effect.active` diff --git a/packages/svelte/src/main/ambient.d.ts b/packages/svelte/src/main/ambient.d.ts index d80e8e432..f32f1863e 100644 --- a/packages/svelte/src/main/ambient.d.ts +++ b/packages/svelte/src/main/ambient.d.ts @@ -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 + * + * + *

in template: {$effect.active()}

+ * ``` + * + * 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; } /**