当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript operators.bufferWhen函数代码示例

本文整理汇总了TypeScript中rxjs/operators.bufferWhen函数的典型用法代码示例。如果您正苦于以下问题:TypeScript bufferWhen函数的具体用法?TypeScript bufferWhen怎么用?TypeScript bufferWhen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了bufferWhen函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

  it('should not break unsubscription chains when result is unsubscribed explicitly', () => {
    const e1 = hot('--a--^---b---c---d---e---f---g---h------|      ');
    const subs =        '^                 !                       ';
    const closings = [
      cold(           '---------------(s|)                       '),
      cold(                          '----------(s|)             '),
      cold(                                    '-------------(s|)')];
    const closeSubs =  ['^              !                          ',
                      '               ^  !                       '];
    const expected =    '---------------x---                       ';
    const unsub =       '                  !                       ';
    const values = {
      x: ['b', 'c', 'd']
    };

    let i = 0;
    const result = e1.pipe(
      mergeMap((x: any) => of(x)),
      bufferWhen(() => closings[i++]),
      mergeMap((x: any) => of(x))
    );

    expectObservable(result, unsub).toBe(expected, values);
    expectSubscriptions(e1.subscriptions).toBe(subs);
    expectSubscriptions(closings[0].subscriptions).toBe(closeSubs[0]);
    expectSubscriptions(closings[1].subscriptions).toBe(closeSubs[1]);
    expectSubscriptions(closings[2].subscriptions).toBe([]);
  });
开发者ID:DallanQ,项目名称:rxjs,代码行数:28,代码来源:bufferWhen-spec.ts

示例2: interval

 observable1 = constructorZone1.run(() => {
   const source = interval(100);
   return source.pipe(bufferWhen(() => {
     expect(Zone.current.name).toEqual(constructorZone1.name);
     return interval(220);
   }));
 });
开发者ID:angular,项目名称:zone.js,代码行数:7,代码来源:rxjs.Observable.buffer.spec.ts

示例3: bufferWhen1

 bufferWhen1() {
   // emit value every 1 second
   const oneSecondInterval = interval(1000);
   // return an observable that emits value every 5 seconds
   const fiveSecondInterval = () => interval(5000);
   // every five seconds, emit buffered values
   const bufferWhenExample = oneSecondInterval.pipe(bufferWhen(fiveSecondInterval));
   // log values
   // ex. output: [0,1,2,3]...[4,5,6,7,8]
   const subscribe = bufferWhenExample.subscribe(val =>
     console.log('Emitted Buffer: ', val)
   );
 }
开发者ID:zwvista,项目名称:SampleMisc,代码行数:13,代码来源:transforming.service.ts

示例4: asDiagram

  asDiagram('bufferWhen')('should emit buffers that close and reopen', () => {
    const e1 = hot('--a--^---b---c---d---e---f---g---------|');
    const e2 = cold(    '--------------(s|)');
    //                               --------------(s|)
    const expected =    '--------------x-------------y-----(z|)';
    const values = {
      x: ['b', 'c', 'd'],
      y: ['e', 'f', 'g'],
      z: [] as string[]
    };

    expectObservable(e1.pipe(bufferWhen(() => e2))).toBe(expected, values);
  });
开发者ID:DallanQ,项目名称:rxjs,代码行数:13,代码来源:bufferWhen-spec.ts


注:本文中的rxjs/operators.bufferWhen函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。