-
Notifications
You must be signed in to change notification settings - Fork 47
docs: mention 3 strats for with(Entity)Resource error handling
#271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
4a484c0
00e2d14
f8152f4
9ece275
452c787
88ff856
964a75f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| --- | ||
| title: withEntityResources() | ||
| ## title: withEntityResources() | ||
| --- | ||
|
|
||
| ```typescript | ||
|
|
@@ -86,6 +86,35 @@ This exposes per-resource members with the resource name as a prefix: | |
| - **Resource members**: `todosValue()`, `todosStatus()`, `todosError()`, `todosIsLoading()`; `projectsValue()`, ... | ||
| - **Entity members**: `todosIds()`, `todosEntityMap()`, `todosEntities()`; `projectsIds()`, `projectsEntityMap()`, `projectsEntities()` | ||
|
|
||
| ## Error Handling | ||
|
|
||
| The behavior of Angular's resources' error handling and the NgRx SignalStore's `getState/patchState` required `withEntityResource` to approach error handling | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO - I phrased this so weird. Once the v21 blog post is more fleshed out, take what was written there and replace some of this awkwardness. |
||
| with a particular strategy unique to the intersection of resources and the Signal Store. | ||
| To prevent resource failures from blocking the store, the Toolkit provides some strategies to handle errors. | ||
|
|
||
| ```ts | ||
| withEntityResource( | ||
| () => ({ | ||
| id: resource({ | ||
| loader: () => Promise.resolve(1), | ||
| defaultValue: 0, | ||
| }), | ||
| }), | ||
| // Other values: 'native' and 'previous value' | ||
| { errorHandling: 'undefined value' }, // default if not specified | ||
| ), | ||
| ``` | ||
|
|
||
| Options: | ||
|
|
||
| 1. `'undfined value'` (default). In the event of an error, the resource's value will be `undefined` | ||
| 1. `'previous value'`. Provided the resource had a previous value, that previous value will be returned. If not, an error is thrown. | ||
| 1. `'native'`. No special handling is provided, inline with default error behavior. | ||
|
|
||
| <!-- TODO - update link when the code is merged --> | ||
|
|
||
| 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). | ||
|
|
||
| ## Component Usage | ||
|
|
||
| ```typescript | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -83,6 +83,35 @@ 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. | ||||||
|
|
||||||
| ## Error Handling | ||||||
|
|
||||||
| The behavior of Angular's resources' error handling and the NgRx SignalStore's `getState/patchState` required `withResource` to approach error handling | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't be that specific. I would just say sometihng like that the error throwing behavior of the native resource causes a deadlock in the error case. That's why withResource comes with a different error handling, which doesn't throw. |
||||||
| with a particular strategy unique to the intersection of resources and the Signal Store. | ||||||
| To prevent resource failures from blocking the store, the Toolkit provides some strategies to handle errors. | ||||||
|
|
||||||
| ```ts | ||||||
| withResource( | ||||||
| () => ({ | ||||||
| id: resource({ | ||||||
| loader: () => Promise.resolve(1), | ||||||
| defaultValue: 0, | ||||||
| }), | ||||||
| }), | ||||||
| // Other values: 'native' and 'previous value' | ||||||
| { errorHandling: 'undefined value' }, // default if not specified | ||||||
| ), | ||||||
| ``` | ||||||
|
|
||||||
| Options: | ||||||
|
|
||||||
| 1. `'undfined value'` (default). In the event of an error, the resource's value will be `undefined` | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 1. `'previous value'`. Provided the resource had a previous value, that previous value will be returned. If not, an error is thrown. | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't mention the condition that it only returns if a previous value exists. It just returns the previous value. A resource always has a value in its initial state. The implementation needs to consider a "non-realsitic" scenario because of TypeScript. |
||||||
| 1. `'native'`. No special handling is provided, inline with default error behavior. | ||||||
|
|
||||||
| <!-- TODO - update link when the code is merged --> | ||||||
|
|
||||||
| 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). | ||||||
|
|
||||||
| ## Component Usage | ||||||
|
|
||||||
| ```typescript | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The complete
withEntityResourceis based on theundefined valuestrategy. I think we just need to here a quick note on that and link towithResourcefor further details.Users cannot change the error handling here, since
withEntityResourceuses the resource internally. It is an implementation detail so to say.