1 回答
TA贡献1807条经验 获得超9个赞
forkJoin你可以这样使用-
const launchSearchQuery = () => {
mainDispatch({
type: ActionTypes.LAUNCH_SEARCH_QUERY,
});
if (mainState.searchSection.searchQuery !== "") {
forkJoin([
// get order details
orderDetailRepository.getOrderDetails(mainState.searchSection.searchQuery),
// get customer details
customerDetailRepository.getCustomerDetails(mainState.searchSection.searchQuery),
// get equipment details
equipmentDetailRepository.getEquipmentDetails(mainState.searchSection.searchQuery),
// get equipment return details
equipmentReturnDetailRepository.getEquipmentReturnDetails(mainState.searchSection.searchQuery)
]).subscribe(([orderDetails, customerDetails, equipMentDetails, equimentReturnDetails]) => {
searchResultCards.push(mapSearchResultCard(orderDetails, DashboardSectionTitles.ORDER_DETAILS));
searchResultCards.push(mapSearchResultCard(customerDetails, DashboardSectionTitles.CUSTOMER_DETAILS));
searchResultCards.push(mapSearchResultCard(equipMentDetails, DashboardSectionTitles.EQUIPMENT_DETAILS));
searchResultCards.push(mapSearchResultCard(equimentReturnDetails, DashboardSectionTitles.EQUIPMENT_RETURN_DETAILS));
// !!! only execute this when all subscriptions are completed !!!
mainDispatch({
type: ActionTypes.SEARCH_QUERY_COMPLETE,
payload: searchResultCards,
});
});
}
};
添加回答
举报