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


TypeScript operators.windowToggle函數代碼示例

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


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

示例1: hot

  () => {
    const e1 = hot('--1--2--^--a--b--c--d--e--f--g--h--|');
    const e1subs =         '^                          !';
    const e2 = cold(       '--------x-------x-------x--|');
    const e2subs =         '^                          !';
    const e3 = cold(               '----------(x|)      ');
    //                                    ----------(x|)
    //                                            ----------(x|)
    const e3subs = [       '        ^         !         ', // eslint-disable-line array-bracket-spacing
                         '                ^         ! ',
                         '                        ^  !'];
    const expected =       '--------x-------y-------z--|';
    const x = cold(                '-c--d--e--(f|)      ');
    const y = cold(                        '--f--g--h-| ');
    const z = cold(                                '---|');
    const values = { x, y, z };

    const source = e1.pipe(windowToggle(e2, (value: string) => {
      expect(value).to.equal('x');
      return e3;
    }));

    expectObservable(source).toBe(expected, values);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
    expectSubscriptions(e2.subscriptions).toBe(e2subs);
    expectSubscriptions(e3.subscriptions).toBe(e3subs);
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:27,代碼來源:windowToggle-spec.ts

示例2: it

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

    let i = 0;
    const result = e1
      .mergeMap((x: string) => of(x))
      .pipe(windowToggle(e2, () => close[i++]))
      .mergeMap(x => of(x));

    expectObservable(result, unsub).toBe(expected, values);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
    expectSubscriptions(e2.subscriptions).toBe(e2subs);
    expectSubscriptions(close[0].subscriptions).toBe(closeSubs[0]);
    expectSubscriptions(close[1].subscriptions).toBe(closeSubs[1]);
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:28,代碼來源:windowToggle-spec.ts

示例3: windowToggle1

  windowToggle1() {
    // emit immediately then every 1s
    const source = timer(0, 1000);
    // toggle window on every 5
    const toggle = interval(5000);
    const example = source.pipe(
      // turn window on every 5s
      windowToggle(toggle, val => interval(val * 1000)),
      tap(_ => console.log('NEW WINDOW!'))
    );

    const subscribeTwo = example
      .pipe(
        // window emits nested observable
        mergeAll()
        /*
                output:
                "NEW WINDOW!"
                5
                "NEW WINDOW!"
                10
                11
                "NEW WINDOW!"
                15
                16
                "NEW WINDOW!"
                20
                21
                22
              */
      )
      .subscribe(val => console.log(val));
  }
開發者ID:zwvista,項目名稱:SampleMisc,代碼行數:33,代碼來源:transforming.service.ts


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