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

feat(signals): add signalState and selectSignal APIs #4007

Merged

Conversation

markostanimirovic
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Closes #3993

Does this PR introduce a breaking change?

[ ] Yes
[x] No

@netlify
Copy link

netlify bot commented Aug 16, 2023

Deploy Preview for ngrx-io canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 11f2b08
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/64dea4b491432500082cd910

export default 0;
export { selectSignal } from './select-signal';
export { signalState } from './signal-state';
export { SignalStateUpdater } from './signal-state-models';
Copy link
Member

Choose a reason for hiding this comment

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

Does this type need to be exported?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it can be used to avoid manual typing when creating custom updaters. For example:

import { SignalStateUpdater } from '@ngrx/signals';

export function addOne<T>(entity: T): SignalStateUpdater<{ entities: T[] }> {
  return (state) => ({ entities: [...state.entities, entity] });
}

// usage:
import { signalState } from '@ngrx/signals';

type State = { entities: User[] };

const usersState = signalState<State>({ entities: [] });

usersState.$update(
  addOne({ name: 'Marko' }),
  addOne({ name: 'Brandon' })
);

@markostanimirovic markostanimirovic merged commit 745d91f into ngrx:main Aug 18, 2023
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

Successfully merging this pull request may close these issues.

@ngrx/signals: Add initial signalState implementation
3 participants