第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 React 中使用 RxJs 鏈接 Observables 的最佳方式

在 React 中使用 RxJs 鏈接 Observables 的最佳方式

繁華開滿天機 2023-03-03 15:49:36
在這種情況下,最好的方法是鏈接 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,    });  };這是藍圖getOrderDetailsexport interface IOrderDetailRepository {  getOrderDetails: (query: string) => Observable<IOrderDetail[]>;}
查看完整描述

1 回答

?
函數(shù)式編程

TA貢獻1807條經(jīng)驗 獲得超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,

                    });

                });

            }

        

          };


查看完整回答
反對 回復 2023-03-03
  • 1 回答
  • 0 關(guān)注
  • 106 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號