-
-
Notifications
You must be signed in to change notification settings - Fork 204
feat: add signal method overloads to select nested keys #1662
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
base: main
Are you sure you want to change the base?
Conversation
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.
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 |
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.
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'] |
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.
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> { |
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.
What about naming it keys instead of args?
state$ | ||
.pipe(select(p as K), takeUntilDestroyed(destroyRef)) | ||
.pipe(select(...(keyFields as [any])), takeUntilDestroyed(destroyRef)) |
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.
Not sure why we dropped the generic cast in favor of [any]?
Enables signal method overloads π
I went with this approach:
TODO: add docs
Fixes #1659
cc @hoebbelsB @edbzn