Replies: 2 comments 14 replies
-
As in the global store, you cannot initialize the store with values from a request. Instead, you would initialize the state with an empty array. Your global store fetches the data asynchronously via an effect. In that effect, you can inject your SignalStore instance and then call the method that sets the entities. Something like @Injectable()
export class GlobalStoreEffect {
readonly #actions = inject(Actions);
readonly #loadService = inject(LoadService);
readonly #store = inject(MySignalStore);
loadData$ = effect(() => {
returnthis.#actions.pipe(
ofType(someAction.load),
switchMap(() => loadService.load()),
tap(data => this.#store.setData(data)),
map(data => someAction.loaded(data)))
}))
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
Ok, but then it should be easy. const GlobalStore = signalStore(withState({blog: blog}))
const CommentStore = signalStore(
withMethods(store => ({
sync: rxMethod<Comment[]>(pipe(tap(comments => patchState(store, {comments}))
})),
withHooks(store => ({
const globalStore = inject(GlobalStore);
onInit() {
store.sync(globalStore.blog.comments);
}
})
) |
Beta Was this translation helpful? Give feedback.
13 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How to implement combine selector but in ngrx/signals,
I have a global store that has an array, this array is fetched from a service,
In the other hand, I have a child store using entity management, I need to initialize the child store with the feched data, how can i do that?
Beta Was this translation helpful? Give feedback.
All reactions