-
Notifications
You must be signed in to change notification settings - Fork 26.3k
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
feat(core): introduce the reactive linkedSignal #58189
Conversation
15305fc
to
0d35dce
Compare
0d35dce
to
cf6c598
Compare
Sorry if I’m missing something obvious here. |
@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 |
cf6c598
to
0b3e663
Compare
0b3e663
to
eae38c3
Compare
eae38c3
to
fb4bd27
Compare
There was a problem hiding this 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;
}
There was a problem hiding this 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
@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
fd24fc9
to
ce7d8c7
Compare
There was a problem hiding this 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
There was a problem hiding this 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
There was a problem hiding this 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
This PR was merged into the repository by commit 8311f00. The changes were merged into the following branches: main |
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? |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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).