From 25766f60bae65792b85134b12361c736cd29ddc9 Mon Sep 17 00:00:00 2001 From: Michael Small Date: Wed, 21 Jan 2026 21:27:35 -0600 Subject: [PATCH 1/4] docs(`withResource`): mention how to patch value --- docs/docs/with-resource.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/docs/with-resource.md b/docs/docs/with-resource.md index e023cea..9eaf901 100644 --- a/docs/docs/with-resource.md +++ b/docs/docs/with-resource.md @@ -83,6 +83,25 @@ With named resources, each resource gets prefixed properties: - **Single resource:** use when your store works with just one data source. - **Named resources:** use when your store is larger and manages multiple entities or async operations. +## Updating + +The state to patch corresponds directly to the name of the resource's value signal. + +```ts +const UserStore = signalStore( + withResource((state) => httpResource(() => `/user/${state.userId}`)), + withResource(({ userId }) => ({ + list: httpResource(() => '/users', { defaultValue: [] }), + })), +); + +// Unnamed resource: `value` +patchState(store, { value: undefined }); + +// Named resource: name prefix + `Value` +patchState(store, { listValue: [] }); +``` + ## Error Handling The error throwing behavior of the native `resource` causes a deadlock in the error case. From 3f20773601eb3d781d7b46cb62eb5793bf6a7f6a Mon Sep 17 00:00:00 2001 From: Michael Small Date: Thu, 22 Jan 2026 20:58:18 -0600 Subject: [PATCH 2/4] docs(`withResource`): new patch values --- docs/docs/with-resource.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/with-resource.md b/docs/docs/with-resource.md index 9eaf901..1cd2f33 100644 --- a/docs/docs/with-resource.md +++ b/docs/docs/with-resource.md @@ -96,10 +96,10 @@ const UserStore = signalStore( ); // Unnamed resource: `value` -patchState(store, { value: undefined }); +patchState(store, { value: { id: 1, name: 'John' } }); // Named resource: name prefix + `Value` -patchState(store, { listValue: [] }); +patchState(store, ({ listValue }) => ({ listValue: [...(listValue ?? []), { id: 1, name: 'John' }] })); ``` ## Error Handling From bcca90ead81fa4eb34b33c8da3ef62e11b137d4d Mon Sep 17 00:00:00 2001 From: Michael Small Date: Sat, 24 Jan 2026 18:23:03 -0600 Subject: [PATCH 3/4] docs: mention `undefined value` type handling --- docs/docs/with-resource.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/docs/with-resource.md b/docs/docs/with-resource.md index 1cd2f33..f8b9978 100644 --- a/docs/docs/with-resource.md +++ b/docs/docs/with-resource.md @@ -99,6 +99,7 @@ const UserStore = signalStore( patchState(store, { value: { id: 1, name: 'John' } }); // Named resource: name prefix + `Value` +// See the "Error Handling" section about why `listValue` has to be treated like it could be undefined. patchState(store, ({ listValue }) => ({ listValue: [...(listValue ?? []), { id: 1, name: 'John' }] })); ``` @@ -130,6 +131,10 @@ Options: Under the hood, `'previous value'` and `'undefined value'` proxy the value. For a detailed explanation for why this is done, check out the [JSDoc for the error handling strategy](https://github.com/angular-architects/ngrx-toolkit/blob/main/libs/ngrx-toolkit/src/lib/with-resource.ts#L402). +The implications of `undefined value` is that the inferred value can be `undefined`, even if there is a `defaultValue` set for the resource. +For example, in the [`Updating`](#updating) section, `listValue` will be inferred as `User[] | undefined`. To be able to infer the type with a gauranteed value, +use `{ errorHandling: 'previous value' }` of `withResource` in conjunction with `defaultValue` of said resource. + ## Component Usage ```typescript From e2ae0f357015ac3ed04fb01383c95270d703561f Mon Sep 17 00:00:00 2001 From: Rainer Hahnekamp Date: Sun, 25 Jan 2026 01:55:02 +0100 Subject: [PATCH 4/4] Update docs/docs/with-resource.md --- docs/docs/with-resource.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/with-resource.md b/docs/docs/with-resource.md index f8b9978..0bc1158 100644 --- a/docs/docs/with-resource.md +++ b/docs/docs/with-resource.md @@ -132,7 +132,7 @@ Options: Under the hood, `'previous value'` and `'undefined value'` proxy the value. For a detailed explanation for why this is done, check out the [JSDoc for the error handling strategy](https://github.com/angular-architects/ngrx-toolkit/blob/main/libs/ngrx-toolkit/src/lib/with-resource.ts#L402). The implications of `undefined value` is that the inferred value can be `undefined`, even if there is a `defaultValue` set for the resource. -For example, in the [`Updating`](#updating) section, `listValue` will be inferred as `User[] | undefined`. To be able to infer the type with a gauranteed value, +For example, in the [`Updating`](#updating) section, `listValue` will be inferred as `User[] | undefined`. To be able to infer the type with a guaranteed value, use `{ errorHandling: 'previous value' }` of `withResource` in conjunction with `defaultValue` of said resource. ## Component Usage