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: add signal method overloads to select nested keys #1662

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eneajaho
Copy link
Member

Enables signal method overloads 🚀

I went with this approach:

moviesLoading = this.state.signal('movies', 'loading');

TODO: add docs

Fixes #1659

cc @hoebbelsB @edbzn

@eneajaho eneajaho added the ✍️ Enhancement New feature or request label Dec 23, 2023
@eneajaho eneajaho self-assigned this Dec 23, 2023
@github-actions github-actions bot added { } State @rx-angular/state related 🛂 Test Unit tests, e2e tests, integration tests, test coverage labels Dec 23, 2023
Copy link
Member

@edbzn edbzn left a comment

Choose a reason for hiding this comment

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

Hey, I left a few questions about the types.

) {
const destroyRef = inject(DestroyRef);

const signalState = {} as SignalStateProxy<State>;
return new Proxy<SignalStateProxy<State>>(signalState, {
get<K extends keyof State>(
target: SignalStateProxy<State>,
p: K | string | symbol
Copy link
Member

Choose a reason for hiding this comment

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

Why removing the generic and union type here?


export type SignalStateProxy<State extends object> = {
[K in keyof State]: Signal<State[K]>;
};

export function createSignalStateProxy<State extends object>(
state$: Observable<State>,
stateFn: <K extends keyof State>(k: K) => State[K]
stateFn: RxState<State>['get']
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain the type change here? I'm not sure why stateFn becomes type of RxState.get

/**
* @internal
*/
signal<R>(...args: string[]): Signal<R> {
Copy link
Member

Choose a reason for hiding this comment

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

What about naming it keys instead of args?

state$
.pipe(select(p as K), takeUntilDestroyed(destroyRef))
.pipe(select(...(keyFields as [any])), takeUntilDestroyed(destroyRef))
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why we dropped the generic cast in favor of [any]?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✍️ Enhancement New feature or request { } State @rx-angular/state related 🛂 Test Unit tests, e2e tests, integration tests, test coverage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: allow state.signal() to accept more than one field in order to increase the depth of selection
2 participants