Skip to content
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

Add linkedSignalState #4639

Open
1 of 2 tasks
Harpush opened this issue Dec 20, 2024 · 2 comments
Open
1 of 2 tasks

Add linkedSignalState #4639

Harpush opened this issue Dec 20, 2024 · 2 comments

Comments

@Harpush
Copy link

Harpush commented Dec 20, 2024

Which @ngrx/* package(s) are relevant/related to the feature request?

signals

Information

Currently signal state is a strong utility to handle state even outside signal store.
The missing part is allowing that state to be a linked signal.

I propose a new linkedSignalState which will allow deriving the state based on another signal.

This will allow resetting the state on signal change - or any other state transformation based on some other signal change.

Describe any alternatives/workarounds you're currently using

Currently either don't use signal state or use an effect to update the state.

I would be willing to submit a PR to fix this issue

  • Yes
  • No
@Harpush
Copy link
Author

Harpush commented Jan 10, 2025

An example:

const a = signal(2);

// The state is based on another signal (linked)
const state = linkedSignalState(() => ({value: a() + 1}));
// or
const state = linkedSignalState({
    source: a,
    computation: (source) => ({value: source + 1})
});

patchState(state, {value: 5}); // Patch state like any other state
console.log(state.value()); // Deep signal

@rainerhahnekamp
Copy link
Contributor

Thank you, @Harpush. Rest assured, we are fully aware of the need for this and are actively discussing various strategies to address it. There are also multiple scenarios where linkedSignal could come into play, and we’re taking those into consideration.

We’re not rushing this—our goal is to ensure we get it right the first time. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants