當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript operators.exhaustMap函數代碼示例

本文整理匯總了TypeScript中rxjs/operators.exhaustMap函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript exhaustMap函數的具體用法?TypeScript exhaustMap怎麽用?TypeScript exhaustMap使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了exhaustMap函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: map

> => (action$, state$, { selectLogFilterQueryAsJson, selectVisibleLogSummary }) => {
  const filterQuery$ = state$.pipe(map(selectLogFilterQueryAsJson));
  const summaryInterval$ = state$.pipe(
    map(selectVisibleLogSummary),
    map(({ start, end }) => (start && end ? getLoadParameters(start, end) : null)),
    filter(isNotNull)
  );

  const shouldLoadBetweenNewInterval$ = action$.pipe(
    filter(logPositionActions.reportVisibleSummary.match),
    filter(
      ({ payload: { bucketsOnPage, pagesBeforeStart, pagesAfterEnd } }) =>
        bucketsOnPage < MINIMUM_BUCKETS_PER_PAGE ||
        pagesBeforeStart < MINIMUM_BUFFER_PAGES ||
        pagesAfterEnd < MINIMUM_BUFFER_PAGES
    ),
    map(({ payload: { start, end } }) => getLoadParameters(start, end))
  );

  const shouldLoadWithNewFilter$ = action$.pipe(
    filter(logFilterActions.applyLogFilterQuery.match),
    withLatestFrom(filterQuery$, (filterQuery, filterQueryString) => filterQueryString)
  );

  return merge(
    shouldLoadBetweenNewInterval$.pipe(
      withLatestFrom(filterQuery$),
      exhaustMap(([{ start, end, bucketSize }, filterQuery]) => [
        loadSummary({
          start,
          end,
          sourceId: 'default',
          bucketSize,
          filterQuery,
        }),
      ])
    ),
    shouldLoadWithNewFilter$.pipe(
      withLatestFrom(summaryInterval$),
      exhaustMap(([filterQuery, { start, end, bucketSize }]) => [
        loadSummary({
          start,
          end,
          sourceId: 'default',
          bucketSize: (end - start) / LOAD_BUCKETS_PER_PAGE,
          filterQuery,
        }),
      ])
    )
  );
};
開發者ID:gingerwizard,項目名稱:kibana,代碼行數:51,代碼來源:epic.ts

示例2: exhaustMap2

  exhaustMap2() {
    const firstInterval = interval(1000).pipe(take(10));
    const secondInterval = interval(1000).pipe(take(2));

    const exhaustSub = firstInterval
      .pipe(
        exhaustMap(f => {
          console.log(`Emission Corrected of first interval: ${f}`);
          return secondInterval;
        })
      )
      /*
        When we subscribed to the first interval, it starts to emit a values (starting 0).
        This value is mapped to the second interval which then begins to emit (starting 0).
        While the second interval is active, values from the first interval are ignored.
        We can see this when firstInterval emits number 3,6, and so on...

          Output:
          Emission of first interval: 0
          0
          1
          Emission of first interval: 3
          0
          1
          Emission of first interval: 6
          0
          1
          Emission of first interval: 9
          0
          1
      */
      .subscribe(s => console.log(s));
  }
開發者ID:zwvista,項目名稱:SampleMisc,代碼行數:33,代碼來源:transforming.service.ts

示例3: map

> => (
  action$,
  state$,
  { selectMetricTimeUpdatePolicyInterval, selectMetricRangeFromTimeRange }
) => {
  const updateInterval$ = state$.pipe(
    map(selectMetricTimeUpdatePolicyInterval),
    filter(isNotNull)
  );

  const range$ = state$.pipe(
    map(selectMetricRangeFromTimeRange),
    filter(isNotNull)
  );

  return action$.pipe(
    filter(startMetricsAutoReload.match),
    withLatestFrom(updateInterval$, range$),
    exhaustMap(([action, updateInterval, range]) =>
      timer(0, updateInterval).pipe(
        map(() =>
          setRangeTime({
            from: moment()
              .subtract(range, 'ms')
              .valueOf(),
            to: moment().valueOf(),
            interval: '1m',
          })
        ),
        takeUntil(action$.pipe(filter(stopMetricsAutoReload.match)))
      )
    )
  );
};
開發者ID:gingerwizard,項目名稱:kibana,代碼行數:34,代碼來源:epic.ts

示例4: it

  it('should not break unsubscription chains when result is unsubscribed explicitly', () => {
    const x = cold(     '--a--b--c--|                               ');
    const xsubs =    '   ^          !                               ';
    const y = cold(               '--d--e--f--|                     ');
    const ysubs: string[] = [];
    const z = cold(                                 '--g--h--i--|   ');
    const zsubs =    '                               ^  !           ';
    const e1 =   hot('---x---------y-----------------z-------------|');
    const e1subs =   '^                                 !           ';
    const expected = '-----a--b--c---------------------g-           ';
    const unsub =    '                                  !           ';

    const observableLookup = { x: x, y: y, z: z };

    const result = e1.pipe(
      mergeMap(x => of(x)),
      exhaustMap(value => observableLookup[value]),
      mergeMap(x => of(x))
    );

    expectObservable(result, unsub).toBe(expected);
    expectSubscriptions(x.subscriptions).toBe(xsubs);
    expectSubscriptions(y.subscriptions).toBe(ysubs);
    expectSubscriptions(z.subscriptions).toBe(zsubs);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });
開發者ID:jaychsu,項目名稱:RxJS,代碼行數:26,代碼來源:exhaustMap-spec.ts

示例5: exhaustMap1

  exhaustMap1() {
    const sourceInterval = interval(1000);
    const delayedInterval = sourceInterval.pipe(delay(10), take(4));

    const exhaustSub = merge(
      //  delay 10ms, then start interval emitting 4 values
      delayedInterval,
      //  emit immediately
      of(true)
    )
      .pipe(exhaustMap(_ => sourceInterval.pipe(take(5))))
      /*
       *  The first emitted value (of(true)) will be mapped
       *  to an interval observable emitting 1 value every
       *  second, completing after 5.
       *  Because the emissions from the delayed interval
       *  fall while this observable is still active they will be ignored.
       *
       *  Contrast this with concatMap which would queue,
       *  switchMap which would switch to a new inner observable each emission,
       *  and mergeMap which would maintain a new subscription for each emitted value.
       */
      //  output: 0, 1, 2, 3, 4
      .subscribe(val => console.log(val));
  }
開發者ID:zwvista,項目名稱:SampleMisc,代碼行數:25,代碼來源:transforming.service.ts

示例6: filter

export const createLogPositionEpic = <State>(): Epic<Action, Action, State, {}> => action$ =>
  action$.pipe(
    filter(startAutoReload.match),
    exhaustMap(({ payload }) =>
      timer(0, payload).pipe(
        map(() => jumpToTargetPositionTime(Date.now())),
        takeUntil(action$.pipe(filter(stopAutoReload.match)))
      )
    )
  );
開發者ID:elastic,項目名稱:kibana,代碼行數:10,代碼來源:epic.ts

示例7: hot

  ('should map-and-flatten each item to an Observable', () => {
    const e1 =    hot('--1-----3--5-------|');
    const e1subs =    '^                  !';
    const e2 =   cold('x-x-x|              ', {x: 10});
    const expected =  '--x-x-x-y-y-y------|';
    const values = {x: 10, y: 30, z: 50};

    const result = e1.pipe(exhaustMap(x => e2.map(i => i * +x)));

    expectObservable(result).toBe(expected, values);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });
開發者ID:jaychsu,項目名稱:RxJS,代碼行數:12,代碼來源:exhaustMap-spec.ts


注:本文中的rxjs/operators.exhaustMap函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。