Skip to content

Commit 00e2d14

Browse files
committed
chore: describe choice/opttions for withResource error handling
1 parent 4a484c0 commit 00e2d14

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

docs/docs/with-entity-resources.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
<!-- TODO - mention error handling strategies -->
2-
31
---
4-
52
## title: withEntityResources()
3+
---
64

75
```typescript
86
import { withEntityResources } from '@angular-architects/ngrx-toolkit';
@@ -88,6 +86,10 @@ This exposes per-resource members with the resource name as a prefix:
8886
- **Resource members**: `todosValue()`, `todosStatus()`, `todosError()`, `todosIsLoading()`; `projectsValue()`, ...
8987
- **Entity members**: `todosIds()`, `todosEntityMap()`, `todosEntities()`; `projectsIds()`, `projectsEntityMap()`, `projectsEntities()`
9088

89+
## Error Handling
90+
91+
<!-- TODO - mention error handling strategies -->
92+
9193
## Component Usage
9294

9395
```typescript

docs/docs/with-resource.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
<!-- TODO - mention error handling strategies -->
2-
31
---
4-
5-
## title: withResource()
2+
title: withResource()
3+
---
64

75
```typescript
86
import { withResource } from '@angular-architects/ngrx-toolkit';
@@ -85,6 +83,35 @@ With named resources, each resource gets prefixed properties:
8583
- **Single resource:** use when your store works with just one data source.
8684
- **Named resources:** use when your store is larger and manages multiple entities or async operations.
8785

86+
## Error Handling
87+
88+
The behavior of Angular's resources' error handling and the NgRx SignalStore's `getState/patchState` required `withResource` to handle error handling with a particular strategy.
89+
To prevent resource failures from blocking the store, the Toolkit provides some strategies to handle errors.
90+
91+
```ts
92+
withResource(
93+
() => ({
94+
id: resource({
95+
loader: () => Promise.resolve(1),
96+
defaultValue: 0,
97+
}),
98+
}),
99+
// Other values: 'native' and 'previous value'
100+
{ errorHandling: 'undefined value' }, // default if not specified
101+
),
102+
```
103+
104+
Options:
105+
106+
1. `'undfined value'` (default). In the event of an error, the resource's value will be `undefined`
107+
1. `'previous value'`. Provided the resource had a previous value, that previous value will be returned. If not, an error is thrown.
108+
1. `'native'`. No special handling is provided, inline with default error behavior.
109+
110+
<!-- TODO - mention both approaches with pros & cons like the jsdoc? link to it? IMO - mention we use a proxy approach while Angular works on error handling and then link to jsdoc -->
111+
<!-- TODO - PROPOSED COPY -->
112+
113+
Under the hood, `'previous value'` and `'undefined value'` proxy the value. For a detailed explanation for why this is done and what a more longterm solution may be with some framework enhancements, check out the [JSDoc for the error handling strategy](https://google.com).
114+
88115
## Component Usage
89116

90117
```typescript

0 commit comments

Comments
 (0)