feat: Controller.fetch returns denoramlized form #2545
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2330 .
Motivation
@taystack @gregor-mueller @tobobo
There is a strong desire to have Controller.fetch return the same value as hooks like useSuspense and useCache would. Furthermore, currently the return type is often 'any' because default RestEndpoint without a process method will have that resolve type.
Solution
The new version simply runs its through denormalize and we use the same typing value as useSuspense.
I realized, denormalize works fine without any entities, so there's no need for any special code - it will construct the expected return values even with 'flat' inputs. This eliminates the need for a more cpu intensive normalize/denormalize step.
This does mean since it has no data from the store, the updated values from something like useCache will likely not match. However, I believe this more closely matches a user's expectation - they simply want that fetches value, but in the same form they expect with responses. This allows utilizing getters, and other fun class values.
Usage
We use the new standard for breaking changes shipping with
/next
exports, with updates to the normal exports in the next breaking version.Note import from
@rest-hooks/react/next