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


TypeScript operators.concatMapTo函數代碼示例

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


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

示例1: it

  it('should support the deprecated resultSelector', () => {
    const results: Array<number[]> = [];

    of(1, 2, 3).pipe(
      concatMapTo(
        of(4, 5, 6),
        (a, b, i, ii) => [a, b, i, ii]
      )
    )
    .subscribe({
      next (value) {
        results.push(value);
      },
      error(err) {
        throw err;
      },
      complete() {
        expect(results).to.deep.equal([
          [1, 4, 0, 0],
          [1, 5, 0, 1],
          [1, 6, 0, 2],
          [2, 4, 1, 0],
          [2, 5, 1, 1],
          [2, 6, 1, 2],
          [3, 4, 2, 0],
          [3, 5, 2, 1],
          [3, 6, 2, 2],
        ]);
      }
    });
  });
開發者ID:MykhailoIskiv,項目名稱:rxjs,代碼行數:31,代碼來源:concatMapTo-spec.ts

示例2: concatMapTo2

  concatMapTo2() {
    // emit value every 2 seconds
    const interval$ = interval(2000);
    // emit value every second for 5 seconds
    const source = interval(1000).pipe(take(5));
    /*
      ***Be Careful***: In situations like this where the source emits at a faster pace
      than the inner observable completes, memory issues can arise.
      (interval emits every 1 second, basicTimer completes every 5)
    */
    //  basicTimer will complete after 5 seconds, emitting 0,1,2,3,4
    const example = interval$.pipe(
      concatMapTo(
        source,
        (firstInterval, secondInterval) => `${firstInterval} ${secondInterval}`
      )
    );
    /*
      output: 0 0
              0 1
              0 2
              0 3
              0 4
              1 0
              1 1
              continued...

    */
    const subscribe = example.subscribe(val => console.log(val));
  }
開發者ID:zwvista,項目名稱:SampleMisc,代碼行數:30,代碼來源:transforming.service.ts

示例3: concatMapTo1

 concatMapTo1() {
   // emit value every 2 seconds
   const sampleInterval = interval(500).pipe(take(5));
   const fakeRequest = of('Network request complete').pipe(delay(3000));
   // wait for first to complete before next is subscribed
   const example = sampleInterval.pipe(concatMapTo(fakeRequest));
   // result
   // output: Network request complete...3s...Network request complete'
   const subscribe = example.subscribe(val => console.log(val));
 }
開發者ID:zwvista,項目名稱:SampleMisc,代碼行數:10,代碼來源:transforming.service.ts

示例4: 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-x-x-xx-x-x-|';
    const values = {x: 10};

    const result = e1.pipe(concatMapTo(e2));

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


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