From cc4af6c98ec25fdae8c353eea667300be4285227 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Tue, 7 Jan 2025 17:03:59 +0100 Subject: [PATCH 1/2] docs: note that `$derived` memoizes output closes #14772 --- documentation/docs/02-runes/03-$derived.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/documentation/docs/02-runes/03-$derived.md b/documentation/docs/02-runes/03-$derived.md index 6b38f9974672..cbc35e944807 100644 --- a/documentation/docs/02-runes/03-$derived.md +++ b/documentation/docs/02-runes/03-$derived.md @@ -19,6 +19,21 @@ Derived state is declared with the `$derived` rune: The expression inside `$derived(...)` should be free of side-effects. Svelte will disallow state changes (e.g. `count++`) inside derived expressions. +Subsequents results of a `$derived` expression are compared against its previous value. If they are referentially the same, the `$derived` won't propagate an update to its dependencies. + +```svelte + + + +``` + + As with `$state`, you can mark class fields as `$derived`. > [!NOTE] Code in Svelte components is only executed once at creation. Without the `$derived` rune, `doubled` would maintain its original value even when `count` changes. From 0321db1abd986aa14adbfb850226bee70e2a17ac Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:49:02 +0100 Subject: [PATCH 2/2] Update documentation/docs/02-runes/03-$derived.md Co-authored-by: Yash Pandit --- documentation/docs/02-runes/03-$derived.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/docs/02-runes/03-$derived.md b/documentation/docs/02-runes/03-$derived.md index cbc35e944807..a51662089d6d 100644 --- a/documentation/docs/02-runes/03-$derived.md +++ b/documentation/docs/02-runes/03-$derived.md @@ -19,7 +19,7 @@ Derived state is declared with the `$derived` rune: The expression inside `$derived(...)` should be free of side-effects. Svelte will disallow state changes (e.g. `count++`) inside derived expressions. -Subsequents results of a `$derived` expression are compared against its previous value. If they are referentially the same, the `$derived` won't propagate an update to its dependencies. +Subsequent results of a `$derived` expression are compared against its previous value. If they are referentially the same, the `$derived` won't propagate an update to its dependencies. ```svelte