Currently, I'm trying to determine whether my implementation of the ngrx and sandbox pattern is effective. Here's the issue I'm facing:
getFiles(userId: number, companyId: number) {
this.fileService.getFiles(userId, companyId).subscribe(res => this.store.dispatch(myaction({files: res})))
}
This function involves calling a service and handling the success through an action dispatch.
In order to call the sandbox function, I need to utilize two selectors in my container-component to retrieve userId (userId$) and companyId (company$), which are required parameters for the sandbox function. My ngOnInit looks like this:
combineLatest([this.company$, this.userId$])
.pipe(
filter(res => res[0] !== null && res[1] !== null),
take(1),
map(res => {
let companyId = res[0].id;
let userId = res[1];
this.sandbox.getfiles(companyId, userId);
})
)
.subscribe();
I'm unsure if this is the right approach or if it leads to nested subscriptions. The challenge arises when I try to avoid subscribing inside the function declaration while still requiring data from the selectors before invoking the sandbox function. What is the recommended solution?