在这种情况下,最好的方法是链接 Observables 并SEARCH_QUERY_COMPLETE在所有订阅完成后分派操作?我注意到这forkJoin已被弃用......
const launchSearchQuery = () => {
mainDispatch({
type: ActionTypes.LAUNCH_SEARCH_QUERY,
});
if (mainState.searchSection.searchQuery !== "") {
// get order details
orderDetailRepository.getOrderDetails(mainState.searchSection.searchQuery).subscribe((response) => {
searchResultCards.push(mapSearchResultCard(response, DashboardSectionTitles.ORDER_DETAILS));
});
// get customer details
customerDetailRepository.getCustomerDetails(mainState.searchSection.searchQuery).subscribe((response) => {
searchResultCards.push(mapSearchResultCard(response, DashboardSectionTitles.CUSTOMER_DETAILS));
});
// get equipment details
equipmentDetailRepository.getEquipmentDetails(mainState.searchSection.searchQuery).subscribe((response) => {
searchResultCards.push(mapSearchResultCard(response, DashboardSectionTitles.EQUIPMENT_DETAILS));
});
// get equipment return details
equipmentReturnDetailRepository
.getEquipmentReturnDetails(mainState.searchSection.searchQuery)
.subscribe((response) => {
searchResultCards.push(mapSearchResultCard(response, DashboardSectionTitles.EQUIPMENT_RETURN_DETAILS));
});
}
// !!! only execute this when all subscriptions are completed !!!
mainDispatch({
type: ActionTypes.SEARCH_QUERY_COMPLETE,
payload: searchResultCards,
});
};
这是蓝图getOrderDetails
export interface IOrderDetailRepository {
getOrderDetails: (query: string) => Observable<IOrderDetail[]>;
}
函数式编程
相关分类