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


TypeScript operators.mergeMapTo函數代碼示例

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


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

示例1: it

  it('should not break unsubscription chains when result is unsubscribed explicitly', () => {
    const source =     cold('-1-2-3----4-|');
    const sourceSubs =      '^        !   ';
    const multicasted = source.pipe(
      mergeMap((x) => of(x)),
      multicast(() => new Subject<string>())
    ) as ConnectableObservable<string>;
    const subscriber1 = hot('a|           ').pipe(mergeMapTo(multicasted));
    const expected1   =     '-1-2-3----   ';
    const subscriber2 = hot('    b|       ').pipe(mergeMapTo(multicasted));
    const expected2   =     '    -3----   ';
    const subscriber3 = hot('        c|   ').pipe(mergeMapTo(multicasted));
    const expected3   =     '        --   ';
    const unsub =           '         u   ';

    expectObservable(subscriber1).toBe(expected1);
    expectObservable(subscriber2).toBe(expected2);
    expectObservable(subscriber3).toBe(expected3);
    expectSubscriptions(source.subscriptions).toBe(sourceSubs);

    // Set up unsubscription action
    let connection: Subscription;
    expectObservable(hot(unsub).pipe(tap(() => {
      connection.unsubscribe();
    }))).toBe(unsub);

    connection = multicasted.connect();
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:28,代碼來源:multicast-spec.ts

示例2: type

  type('should support type signatures', () => {
    let o: Observable<number>;
    let m: Observable<string>;

    /* tslint:disable:no-unused-variable */
    let a1: Observable<string> = o.pipe(mergeMapTo(m));
    let a2: Observable<string> = o.pipe(mergeMapTo(m, 3));
    /* tslint:enable:no-unused-variable */
  });
開發者ID:MykhailoIskiv,項目名稱:rxjs,代碼行數:9,代碼來源:mergeMapTo-spec.ts

示例3: it

  it('should disconnect when last subscriber unsubscribes', () => {
    const source =     cold(   '-1-2-3----4-|');
    const sourceSubs =      '   ^        !   ';
    const shared = source.pipe(share());
    const subscriber1 = hot('   a|           ').pipe(mergeMapTo(shared));
    const unsub1 =          '          !     ';
    const expected1   =     '   -1-2-3--     ';
    const subscriber2 = hot('       b|       ').pipe(mergeMapTo(shared));
    const unsub2 =          '            !   ';
    const expected2   =     '       -3----   ';

    expectObservable(subscriber1, unsub1).toBe(expected1);
    expectObservable(subscriber2, unsub2).toBe(expected2);
    expectSubscriptions(source.subscriptions).toBe(sourceSubs);
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:15,代碼來源:share-spec.ts

示例4: it

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

    of(1, 2, 3).pipe(
      mergeMapTo(
        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,代碼來源:mergeMapTo-spec.ts

示例5: cold

  'but is unsubscribed explicitly and early', () => {
    const source =     cold('-1-2-3----4-|');
    const sourceSubs =      '^        !   ';
    const shared = source.pipe(share());
    const unsub =           '         !   ';
    const subscriber1 = hot('a|           ').pipe(mergeMapTo(shared));
    const expected1   =     '-1-2-3----   ';
    const subscriber2 = hot('    b|       ').pipe(mergeMapTo(shared));
    const expected2   =     '    -3----   ';
    const subscriber3 = hot('        c|   ').pipe(mergeMapTo(shared));
    const expected3   =     '        --   ';

    expectObservable(subscriber1, unsub).toBe(expected1);
    expectObservable(subscriber2, unsub).toBe(expected2);
    expectObservable(subscriber3, unsub).toBe(expected3);
    expectSubscriptions(source.subscriptions).toBe(sourceSubs);
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:17,代碼來源:share-spec.ts


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