亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

@deprecated 的 combineLatest 重構——不再支持 resultSele

@deprecated 的 combineLatest 重構——不再支持 resultSele

千巷貓影 2023-04-20 16:54:44
角度材料文檔應用程序中包含以下代碼片段:    // Combine params from all of the path into a single object.    this.params = combineLatest(      this._route.pathFromRoot.map(route => route.params),      Object.assign);TSLint 刪除了combineLatest這條消息:@deprecated — 不再支持 resultSelector,而是通過管道映射應該如何解決?此外,如果您了解所使用的技術,那么一個簡單的詳細示例會很棒。這是一個代碼鏈接:https://github.com/angular/material.angular.io/blob/master/src/app/pages/component-category-list/component-category-list.ts
查看完整描述

3 回答

?
qq_笑_17

TA貢獻1818條經驗 獲得超7個贊

combineLatest(observables, resultSelector)

通常可以替換為


combineLatest(observables).pipe(

  map(resultSelector)

)

但這是否以相同的方式工作取決于您resultSelector接受的參數。combineLatest(observables)發出一個數組,當你使用已棄用的 resultSelector 時,RxJs 會自動傳播這個數組。


return isArray(args) ? fn(...args) : fn(args); // fn is your resultSelector

AsObject.assign根據您提供的是數組還是多個值返回不同的值,您必須手動展開數組。


combineLatest(observables).pipe(

  map(items => Object.assign({}, ...items))

)


查看完整回答
反對 回復 2023-04-20
?
千萬里不及你

TA貢獻1784條經驗 獲得超9個贊

結果選擇器只是一個可用于更改輸出形狀的函數。


因此,您可以簡單地省略結果選擇器參數并使用地圖來轉換形狀:


    this.params = combineLatest(

      this._route.pathFromRoot.map(route => route.params)

    ).pipe(

        map(Object.assign)

    );

結果選擇器的一個常見用途(對我來說)是將數組作為具有命名屬性的對象返回,所以像這樣:


// 舊方法


myObs$ = combineLatest(

   [src1$, src2$, src3$], 

   ([src1, src2, src3]) => ({src1, src2, src3})

);

// 新方法


myObs$ = combineLatest(src1$, src2$, src3$)

    .pipe(

       map(([src1, src2, src3]) => ({src1, src2, src3}))

    );


查看完整回答
反對 回復 2023-04-20
?
慕少森

TA貢獻2019條經驗 獲得超9個贊

pipe結果并改用map運算符,例如:

combineLatest(this._route.pathFromRoot.map(route?=>?route.params)).pipe(?
?map(Object.assign)
);

此外,不確定代碼的意圖,因為它似乎正在調用Object.assign一個新的數組引用,不確定為什么這是必要的,但這并不完全相關。


查看完整回答
反對 回復 2023-04-20
  • 3 回答
  • 0 關注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號