1. 程式人生 > >RxJS Observable - switch && switchMap

RxJS Observable - switch && switchMap

map -o body each cti call 返回 higher tput

  1. "switch" subscribes to an Observable that emits Observables, also known as a higher-order Observable.
    解釋: “ that emits Observables” 作為前面 “an Observable” 的修飾從句。

  2. Each time it observes one of these emitted inner Observables,
    the output Observable subscribes to the inner Observable and begins emitting the items emitted by that.

    解釋: “the output Observable subscribes to the inner Observable and begins emitting the items emitted by that.” 補全的寫法應該是:
    “the output Observable subscribes to the inner Observable and (the output) begins emitting the items emitted by (the inner Observable).” 去掉的“that”其實就是“the inner Observable”

  3. Returns an Observable that emits items based on applying a function that you supply to each item emitted by the source Observable, where that function returns an (so-called "inner") Observable.

    分三個階段來看:
    第一階段:Returns an Observable that (1. blah, blah, blah....) ;
    解釋: 返回一個Observable
    第二階段:Returns an Observable that emits items (2. blah, blah, blah....) emitted by the source Observable
    解釋:返回一個會emits items的Observable。
    這些 items 是 emited 自 the source Observable 的。
    (說明是兩層Observable, 即 higher-order Observable)
    第三階段:(2. blah, blah, blah....) 所指代的那一段:based on applying a function that you supply to each item
    解釋:第二階段中 每個 item 都是由你所提供的(自定義) function 加工過的

RxJS Observable - switch && switchMap