Enhance SignalStore to easily connect reactive sources #4415
michaelbe812
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
Hello, hello @mikelgo :) So I think we should use the const store = signalStore(
withState<{
a: any[],
b: boolean,
s: string
}>({
a: [],
b: false,
s: ''
}),
withMethods(store => ({
updateB: rxMethod<boolean>(pipe(tap(b => patchState(store, {b})))
})
)
@Component({
//...
providers: [store]
})
export class AppComponent {
store = inject(store)
constructor() {
effect(() => {
console.log({b: this.store.b()})
});
this.store.updateB(interval(1000).pipe(take(3), map(v => !!(v % 2)))
}
} It is a little bit different. Especially, with simple commands, I've experienced that If I could do something like Turns out, that those "one-line commands" happen very often. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
I would like to propose an idea to enhance the SignalStore with some ergonomic capabilities on connecting reactive sources like observables or signals.
As of today if I'm not wrong we need to manually wire together e.g. observables to update the state:
My proposal is a
withConnect
-Feature which allows to easily connect any kind of observable or signalAdditionally I propose that when the
withConnect
-feature is used also aconnect
-method with the same functionality is added to the store instance, so that we can also do:As inspiration for the connect/withConnect method I had a look at RxState, despite they are offering other overloads.
Beta Was this translation helpful? Give feedback.
All reactions