當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。