Skip to content

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

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

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

Conversation

@alxhub
Copy link
Copy Markdown
Member

@alxhub alxhub commented Jan 21, 2025

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
@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
Copy link
Copy Markdown
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

Reviewed-for: public-api

Copy link
Copy Markdown
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

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

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