From 2377d409a18271a748b76694016ad59b43583ca8 Mon Sep 17 00:00:00 2001 From: mizulu <202852165+mizulu@users.noreply.github.com> Date: Wed, 23 Apr 2025 23:59:34 -0400 Subject: [PATCH 1/3] remove vague addition --- src/routes/concepts/stores.mdx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/routes/concepts/stores.mdx b/src/routes/concepts/stores.mdx index edfd74d3ce..28cea9a22b 100644 --- a/src/routes/concepts/stores.mdx +++ b/src/routes/concepts/stores.mdx @@ -355,8 +355,6 @@ It receives the old value and index as arguments, providing the flexibility to m setStore("users", (user) => user.username.startsWith("t"), "loggedIn", false) ``` -In addition to [`.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith), you can use other array methods like [`.find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) to filter for the values that you need. - ## Modifying objects When using store setters to modify objects, if a new value is an object, it will be shallow merged with the existing value. From b09489a64be7e227fce9c7458ffca34f89ada64d Mon Sep 17 00:00:00 2001 From: mizulu <202852165+mizulu@users.noreply.github.com> Date: Wed, 30 Apr 2025 04:34:11 +0000 Subject: [PATCH 2/3] // Update users with usernames starting with "t" --- src/routes/concepts/stores.mdx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/routes/concepts/stores.mdx b/src/routes/concepts/stores.mdx index 28cea9a22b..97340bc85b 100644 --- a/src/routes/concepts/stores.mdx +++ b/src/routes/concepts/stores.mdx @@ -347,12 +347,20 @@ setStore("users", 3, "loggedIn" , (loggedIn) => !loggedIn) ### Filtering values -In scenarios where you want to update elements in an array based on a specific condition, you can pass a function as an argument. -This function will act as a filter, allowing you to select elements that satisfy the condition. -It receives the old value and index as arguments, providing the flexibility to make conditional updates. +To update elements in an array based on specific conditions, you can pass a function as an argument. +This function will act as a filter, It receives the old value and index, giving you flexibility to apply logic that targets specific cases. +This might include using methods like `.startsWith()`, `includes()`, or other comparison techniques to determine which elements should be updated. ```jsx +// update users with username that starts with "t" setStore("users", (user) => user.username.startsWith("t"), "loggedIn", false) + +// update users with location "Canada" +setStore("users", (user) => user.location == "Canada" , "loggedIn", false) + +// update users with id 1, 2 or 3 +let ids = [1,2,3] +setStore("users", (user) => ids.includes(user.id) , "loggedIn", false) ``` ## Modifying objects From 36c61c4fb6efe6f59b293a4bcaf73459496110b1 Mon Sep 17 00:00:00 2001 From: mizulu <202852165+mizulu@users.noreply.github.com> Date: Wed, 30 Apr 2025 23:35:43 -0400 Subject: [PATCH 3/3] apply suggested changes Co-authored-by: Sarah --- src/routes/concepts/stores.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/concepts/stores.mdx b/src/routes/concepts/stores.mdx index 97340bc85b..ec7a71f885 100644 --- a/src/routes/concepts/stores.mdx +++ b/src/routes/concepts/stores.mdx @@ -348,7 +348,7 @@ setStore("users", 3, "loggedIn" , (loggedIn) => !loggedIn) ### Filtering values To update elements in an array based on specific conditions, you can pass a function as an argument. -This function will act as a filter, It receives the old value and index, giving you flexibility to apply logic that targets specific cases. +This function acts as a filter, receiving the old value and index, and gives you the flexibility to apply logic that targets specific cases. This might include using methods like `.startsWith()`, `includes()`, or other comparison techniques to determine which elements should be updated. ```jsx