Skip to content

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 requested a review from hoebbelsB December 23, 2023 18:51
@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.

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 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?

target[key] = _signal;
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

3 participants