当前位置: 首页>>代码示例>>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;未经允许,请勿转载。