Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(core): introduce the reactive linkedSignal #58189

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

Conversation

pkozlowski-opensource
Copy link
Member

This change introduces the new reactive primitive: linkedSignal.

A linkedSignal represents state (hence the signal in the name) that is reset based on the provided computation. Conceptually it is a state that is maintained / valid only in the context of another source signal (context is deteremined by a computation).

@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: core Issues related to the framework runtime labels Oct 14, 2024
@ngbot ngbot bot added this to the Backlog milestone Oct 14, 2024
@pkozlowski-opensource pkozlowski-opensource added the target: minor This PR is targeted for the next minor release label Oct 14, 2024
@angular-robot angular-robot bot added area: core Issues related to the framework runtime and removed area: core Issues related to the framework runtime labels Oct 14, 2024
@angular-robot angular-robot bot added area: core Issues related to the framework runtime and removed area: core Issues related to the framework runtime labels Oct 14, 2024
@dostarora97
Copy link

Sorry if I’m missing something obvious here.
But how is this different from computed() signal ?

@Armenvardanyan95
Copy link
Contributor

Armenvardanyan95 commented Oct 15, 2024

Sorry if I’m missing something obvious here. But how is this different from computed() signal ?

@dostarora97 This will be writable. Computed signals are only readable, so they completely depend on their tracked signals. With this, you can set your own values, but it will be overwritten if the source signal changes its value

@angular-robot angular-robot bot added area: core Issues related to the framework runtime and removed area: core Issues related to the framework runtime labels Oct 15, 2024
@angular-robot angular-robot bot added area: core Issues related to the framework runtime and removed area: core Issues related to the framework runtime labels Oct 15, 2024
@ngbot ngbot bot modified the milestone: Backlog Oct 15, 2024
@angular-robot angular-robot bot added area: core Issues related to the framework runtime and removed area: core Issues related to the framework runtime labels Oct 15, 2024
@pullapprove pullapprove bot added requires: TGP This PR requires a passing TGP before merging is allowed and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 16, 2024
Copy link

@chrisrocco chrisrocco left a comment

Choose a reason for hiding this comment

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

I believe it's possible to construct this API using existing primitives. Was this approach considered, and/or what are the benefits of creating a new subclass of ReactiveNode instead? Performance? DevTools?

Something like this (plus the other features) -

function linkedSignal(src: Signal) {
  const wrapped = () => signal(src());
  const getter = () => wrapped()[0]();
  const setter = (next) => wrapped()[1](next);
  getter.set = setter;
  return getter;
}

Copy link
Member

@alxhub alxhub 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

@pkozlowski-opensource
Copy link
Member Author

@chrisrocco there are some complications with implementing this purely in the user-land: mostly around previous values and equality. Will follow up with you offline.

This change introduces the new reactive primitive: linkedSignal.

A linkedSignal represents state (hence the signal in the name)
that is reset based on the provided computation. Conceptually
it is a state that is maintained / valid only in the context of
another source signal (context is deteremined by a computation).

Closes angular#55673
@pullapprove pullapprove bot removed the requires: TGP This PR requires a passing TGP before merging is allowed label Oct 17, 2024
@angular-robot angular-robot bot added area: core Issues related to the framework runtime and removed area: core Issues related to the framework runtime labels Oct 17, 2024
@pkozlowski-opensource pkozlowski-opensource added the action: review The PR is still awaiting reviews from at least one requested reviewer label Oct 17, 2024
@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 Oct 17, 2024
Copy link
Member

@alxhub alxhub 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
Contributor

@thePunderWoman thePunderWoman 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, fw-core

Copy link
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

@devversion
Copy link
Member

This PR was merged into the repository by commit 8311f00.

The changes were merged into the following branches: main

@Ookamini95
Copy link

Ookamini95 commented Nov 8, 2024

Not the best programmer to hear from, but i belive "linked" would keep close to the style of "signal" and "computed". Nothing wrong with longer names, but if you really want to go for it why not a more intuitive name like "writableComputed"? What is the reasoning behind "linkedSignal" naming convention?

@angular-automatic-lock-bot
Copy link

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 Dec 9, 2024
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.

9 participants