{{ message }}
Repository navigation
Conversation
pullapprove
Bot
requested review from
AndrewKushnir,
pkozlowski-opensource and
thePunderWoman
December 3, 2024 14:41
alxhub
force-pushed
the
experimental/resource/fixes
branch
from
December 3, 2024 14:54
0bfb183 to
8923549
Compare
Member
There was a problem hiding this comment.
mega-nit: new line to add spacing between tests
pkozlowski-opensource
approved these changes
Dec 3, 2024
pkozlowski-opensource
left a comment
Member
There was a problem hiding this comment.
LGTM
Reviewed-for: public-api
Reviewed-for: fw-core
alxhub
force-pushed
the
experimental/resource/fixes
branch
from
December 3, 2024 15:03
8923549 to
c9d2703
Compare
thePunderWoman
approved these changes
Dec 3, 2024
thePunderWoman
left a comment
Contributor
There was a problem hiding this comment.
reviewed-for: public-api
|
I really like the defaultValue on resource. Having not an Thanks for that! |
alxhub
force-pushed
the
experimental/resource/fixes
branch
from
December 19, 2024 12:39
c9d2703 to
b4c6e01
Compare
alxhub
force-pushed
the
experimental/resource/fixes
branch
from
January 14, 2025 14:13
b4c6e01 to
62bdd74
Compare
Originally the `T` in `Resource<T>` represented the resolved type of the resource, and `undefined` was explicitly added to this type in the `.value` signal. This turned out to be problematic, as it wasn't possible to write a type for a resource which didn't return `undefined` values. Such a type is useful for 2 reasons: 1. to support narrowing of the resource type when `Resource.hasValue()` returns `true`. 2. for resources which use a different value instead of `undefined` to represent not having a value (for example, array resources which want to use `[]` as their default). Instead, this commit changes `resource()` and `rxResource()` to return an explicit `ResourceRef<T|undefined>`, and removes the union with `undefined` from all types related to the resource's value. This way, it's trivially possible to write `Resource<T>` to represent resources where `.value` only returns `T`. `hasValue()` then actually works to perform narrowing, by narrowing the resource type to `Exclude<T, undefined>`.
When the reactive `request` of a resource() notifies, it transitions to the
Loading state, fires the loader, and eventually transitions to Resolved.
With the prior implementation, a change of the `request` will queue the
effect, but the state remains unchanged until the effect actually runs. For
a brief period, the resource is in a state where the request has changed,
but the state has yet to update.
This is problematic if we want to use resources in certain contexts where we
care about the state of the resource in a synchronous way. For example, an
async validator backed by a resource might be checked after an update:
```
value.set(123);
if (validator.value()) {
// value is still valid, even though the resource is dirty and will soon
// flip to loading state (returning value(): undefined) while revalidating
}
```
To address this timing concern, `linkedSignal()` is used within the
`resource()` to synchronously transition the state in response to the
request changing. This ensures any followup reads see a consistent view of
the resource regardless of whether the effect has run.
This also addresses a race condition where `.set()` behaves differently on a
`resource()` depending on whether or not the effect has run.
alxhub
force-pushed
the
experimental/resource/fixes
branch
from
January 15, 2025 19:11
62bdd74 to
f21a303
Compare
Member
Author
|
Caretaker: this PR is sensitive to backsliding. we need to patch cl/716243172 so far (and potentially more depending on presubmit failures). |
Contributor
|
This PR was merged into the repository by commit 01fffdb. The changes were merged into the following branches: main, 19.1.x |
AndrewKushnir
pushed a commit
that referenced
this pull request
Jan 16, 2025
…gs (#59024) Originally the `T` in `Resource<T>` represented the resolved type of the resource, and `undefined` was explicitly added to this type in the `.value` signal. This turned out to be problematic, as it wasn't possible to write a type for a resource which didn't return `undefined` values. Such a type is useful for 2 reasons: 1. to support narrowing of the resource type when `Resource.hasValue()` returns `true`. 2. for resources which use a different value instead of `undefined` to represent not having a value (for example, array resources which want to use `[]` as their default). Instead, this commit changes `resource()` and `rxResource()` to return an explicit `ResourceRef<T|undefined>`, and removes the union with `undefined` from all types related to the resource's value. This way, it's trivially possible to write `Resource<T>` to represent resources where `.value` only returns `T`. `hasValue()` then actually works to perform narrowing, by narrowing the resource type to `Exclude<T, undefined>`. PR Close #59024
AndrewKushnir
pushed a commit
that referenced
this pull request
Jan 16, 2025
When the reactive `request` of a resource() notifies, it transitions to the
Loading state, fires the loader, and eventually transitions to Resolved.
With the prior implementation, a change of the `request` will queue the
effect, but the state remains unchanged until the effect actually runs. For
a brief period, the resource is in a state where the request has changed,
but the state has yet to update.
This is problematic if we want to use resources in certain contexts where we
care about the state of the resource in a synchronous way. For example, an
async validator backed by a resource might be checked after an update:
```
value.set(123);
if (validator.value()) {
// value is still valid, even though the resource is dirty and will soon
// flip to loading state (returning value(): undefined) while revalidating
}
```
To address this timing concern, `linkedSignal()` is used within the
`resource()` to synchronously transition the state in response to the
request changing. This ensures any followup reads see a consistent view of
the resource regardless of whether the effect has run.
This also addresses a race condition where `.set()` behaves differently on a
`resource()` depending on whether or not the effect has run.
PR Close #59024
AndrewKushnir
pushed a commit
that referenced
this pull request
Jan 16, 2025
When the reactive `request` of a resource() notifies, it transitions to the
Loading state, fires the loader, and eventually transitions to Resolved.
With the prior implementation, a change of the `request` will queue the
effect, but the state remains unchanged until the effect actually runs. For
a brief period, the resource is in a state where the request has changed,
but the state has yet to update.
This is problematic if we want to use resources in certain contexts where we
care about the state of the resource in a synchronous way. For example, an
async validator backed by a resource might be checked after an update:
```
value.set(123);
if (validator.value()) {
// value is still valid, even though the resource is dirty and will soon
// flip to loading state (returning value(): undefined) while revalidating
}
```
To address this timing concern, `linkedSignal()` is used within the
`resource()` to synchronously transition the state in response to the
request changing. This ensures any followup reads see a consistent view of
the resource regardless of whether the effect has run.
This also addresses a race condition where `.set()` behaves differently on a
`resource()` depending on whether or not the effect has run.
PR Close #59024
PrajaktaB27
pushed a commit
to PrajaktaB27/angular
that referenced
this pull request
Feb 7, 2025
…gs (angular#59024) Originally the `T` in `Resource<T>` represented the resolved type of the resource, and `undefined` was explicitly added to this type in the `.value` signal. This turned out to be problematic, as it wasn't possible to write a type for a resource which didn't return `undefined` values. Such a type is useful for 2 reasons: 1. to support narrowing of the resource type when `Resource.hasValue()` returns `true`. 2. for resources which use a different value instead of `undefined` to represent not having a value (for example, array resources which want to use `[]` as their default). Instead, this commit changes `resource()` and `rxResource()` to return an explicit `ResourceRef<T|undefined>`, and removes the union with `undefined` from all types related to the resource's value. This way, it's trivially possible to write `Resource<T>` to represent resources where `.value` only returns `T`. `hasValue()` then actually works to perform narrowing, by narrowing the resource type to `Exclude<T, undefined>`. PR Close angular#59024
PrajaktaB27
pushed a commit
to PrajaktaB27/angular
that referenced
this pull request
Feb 7, 2025
When the reactive `request` of a resource() notifies, it transitions to the
Loading state, fires the loader, and eventually transitions to Resolved.
With the prior implementation, a change of the `request` will queue the
effect, but the state remains unchanged until the effect actually runs. For
a brief period, the resource is in a state where the request has changed,
but the state has yet to update.
This is problematic if we want to use resources in certain contexts where we
care about the state of the resource in a synchronous way. For example, an
async validator backed by a resource might be checked after an update:
```
value.set(123);
if (validator.value()) {
// value is still valid, even though the resource is dirty and will soon
// flip to loading state (returning value(): undefined) while revalidating
}
```
To address this timing concern, `linkedSignal()` is used within the
`resource()` to synchronously transition the state in response to the
request changing. This ensures any followup reads see a consistent view of
the resource regardless of whether the effect has run.
This also addresses a race condition where `.set()` behaves differently on a
`resource()` depending on whether or not the effect has run.
PR Close angular#59024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.

No description provided.