Skip to content

feat(core): support default value in resource() - #59655

Closed
alxhub wants to merge 1 commit into
angular:mainfrom
alxhub:experimental/resource/default-value
Closed

feat(core): support default value in resource()#59655
alxhub wants to merge 1 commit into
angular:mainfrom
alxhub:experimental/resource/default-value

Conversation

@alxhub

@alxhub alxhub commented Jan 21, 2025

Copy link
Copy Markdown
Member

feat(core): support default value in resource()

Before resource() resolves, its value is in an unknown state. By default it returns undefined in these scenarios, so the type of .value() includes undefined.

This commit adds a defaultValue option to resource() and rxResource() which overrides this default. When provided, an unresolved resource will return this value instead of undefined, which simplifies the typing of .value().

@angular-robot angular-robot Bot added detected: feature PR contains a feature commit area: core Issues related to the framework runtime labels Jan 21, 2025
@ngbot ngbot Bot added this to the Backlog milestone Jan 21, 2025
Comment thread packages/core/rxjs-interop/src/rx_resource.ts Outdated
@alxhub
alxhub force-pushed the experimental/resource/default-value branch from 14c1a0e to 9c705d5 Compare January 21, 2025 23:12
@alxhub alxhub added target: minor This PR is targeted for the next minor release action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 21, 2025
@alxhub alxhub changed the title Experimental/resource/default value feat(core): support default value in resource() Jan 21, 2025

@AndrewKushnir AndrewKushnir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: public-api

Comment thread packages/core/test/resource/resource_spec.ts Outdated

@pkozlowski-opensource pkozlowski-opensource left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Reviewed-for: public-api
Reviewed-for: fw-core

Comment thread packages/core/test/resource/resource_spec.ts Outdated
Before `resource()` resolves, its value is in an unknown state. By default
it returns `undefined` in these scenarios, so the type of `.value()`
includes `undefined`.

This commit adds a `defaultValue` option to `resource()` and `rxResource()`
which overrides this default. When provided, an unresolved resource will
return this value instead of `undefined`, which simplifies the typing of
`.value()`.
@alxhub
alxhub force-pushed the experimental/resource/default-value branch from 9c705d5 to 14183ec Compare January 23, 2025 15:54
@alxhub alxhub added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 23, 2025
@pkozlowski-opensource

Copy link
Copy Markdown
Member

This PR was merged into the repository by commit 1685164.

The changes were merged into the following branches: main

PrajaktaB27 pushed a commit to PrajaktaB27/angular that referenced this pull request Feb 7, 2025
Before `resource()` resolves, its value is in an unknown state. By default
it returns `undefined` in these scenarios, so the type of `.value()`
includes `undefined`.

This commit adds a `defaultValue` option to `resource()` and `rxResource()`
which overrides this default. When provided, an unresolved resource will
return this value instead of `undefined`, which simplifies the typing of
`.value()`.

PR Close angular#59655
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Feb 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants