In my current project, I am working on the "Effect" feature. This involves loading new data from a REST endpoint and then dispatching an action to update the store with the received data. In addition to composing the "searchUrl", there is also some computation involved in determining the value of "newCurrentPage".
I'm trying to figure out how to pass the value of "newCurrentPage" along with the search request when using the following operators:
The code snippet looks like this:
@Effect()
tablePageChanged = this.actions$
.pipe(
ofType(action.tablePageChanged ),
withLatestFrom(this.store.select('tableData')),
switchMap(([action, tableData]) => {
let newCurrentPage: number;
let searchUrl: string;
switch (action.navPage) {
case NavigationPage.First:
newCurrentPage = 1;
searchUrl = tableData.devsTable.firstUrl;
break;
case NavigationPage.Previous:
newCurrentPage = tableData.devsTable.currentPage - 1;
searchUrl = tableData.devsTable.previousUrl;
break;
case NavigationPage.Next:
newCurrentPage = tableData.devsTable.currentPage + 1;
searchUrl = tableData.devsTable.nextUrl;
break;
case NavigationPage.Last:
newCurrentPage = Math.ceil(tableData.devsTable.totalRecords / tableData.devsTable.pageSize);
searchUrl = tableData.devsTable.lastUrl;
break;
default:
break;
}
// At this point, I would like to return the 'newCurrentPage' as well, so that it can be passed to 'handleSuccessfulResponse' later
return this.http.get<UserSearchResponse>(searchUrl, {observe: 'response'});
}),
withLatestFrom(this.store.select('tableData')),
map(([response, tableData]) => {
// Here, I need to access the 'newCurrentPage' value to pass it to the 'handleSuccessfulResponse' function
return this.handleSuccessfulResponse(response, tableData);
})
);
I am still trying to fully grasp RxJS, so if you could provide clear explanations, it would be greatly appreciated. Thanks!