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


TypeScript operators.multicast函數代碼示例

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


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

示例1: it

  it('should multicast a ConnectableObservable', (done) => {
    const expected = [1, 2, 3, 4];

    const source = new Subject<number>();
    const connectable = source.pipe(multicast(new Subject<number>())) as ConnectableObservable<number>;
    const replayed = connectable.pipe(multicast(new ReplaySubject<number>())) as ConnectableObservable<number>;

    connectable.connect();
    replayed.connect();

    source.next(1);
    source.next(2);
    source.next(3);
    source.next(4);
    source.complete();

    replayed.pipe(
      tap({
        next(x) {
          expect(x).to.equal(expected.shift());
        },
        complete() {
          expect(expected.length).to.equal(0);
        }
      })
    ).subscribe(null, done, done);
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:27,代碼來源:multicast-spec.ts

示例2: type

 type('should infer the type for the pipeable operator', () => {
   /* tslint:disable:no-unused-variable */
   const source = of<number>(1, 2, 3);
   // TODO: https://github.com/ReactiveX/rxjs/issues/2972
   const result: ConnectableObservable<number> = multicast(() => new Subject<number>())(source);
   /* tslint:enable:no-unused-variable */
 });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:7,代碼來源:multicast-spec.ts

示例3: multicast1

  multicast1() {
    // emit every 2 seconds, take 5
    const source = interval(2000).pipe(take(5));

    const example = source.pipe(
      // since we are multicasting below, side effects will be executed once
      tap(() => console.log('Side Effect #1')),
      mapTo('Result!')
    );

    // subscribe subject to source upon connect()
    const multi = example.pipe(multicast(() => new Subject())) as ConnectableObservable<string>;
    /*
      subscribers will share source
      output:
      "Side Effect #1"
      "Result!"
      "Result!"
      ...
    */
    const subscriberOne = multi.subscribe(val => console.log(val));
    const subscriberTwo = multi.subscribe(val => console.log(val));
    // subscribe subject to source
    multi.connect();
  }
開發者ID:zwvista,項目名稱:SampleMisc,代碼行數:25,代碼來源:connectable.service.ts


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