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


TypeScript operators.pairwise函数代码示例

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


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

示例1: it

 it('should hide all expanded menu items', (done) => {
   const { fixture, menuService } = createSingleMenuComponent([
     {
       title: 'Menu item collapsed',
       children: [{ title: 'Menu item inner' }],
     },
     {
       title: 'Menu item expanded 1',
       expanded: true,
       children: [{ title: 'Menu item inner' }],
     },
     {
       title: 'Menu item expanded 2',
       expanded: true,
       children: [{ title: 'Menu item inner' }],
     },
   ]);
   menuService.onSubmenuToggle()
     .pipe(pairwise(), take(1))
     .subscribe(([menuBagFirstCollapsed, menuBagSecondCollapsed]: NbMenuBag[]) => {
       expect(menuBagFirstCollapsed.item.title).toEqual('Menu item expanded 1');
       expect(menuBagSecondCollapsed.item.title).toEqual('Menu item expanded 2');
       done();
     });
   menuService.collapseAll();
   fixture.detectChanges();
 }, 1000);
开发者ID:kevinheader,项目名称:nebular,代码行数:27,代码来源:menu.spec.ts

示例2: ngxsOnInit

  ngxsOnInit({ dispatch }: StateContext<ShopProductsModel>) {
    concat(
      this.stateService.getInitialState('', 'products').pipe(take(1)),
      /* LOGIN: */
      this.store$.select(UserState.isLoggedIn).pipe(
        pairwise(),
        filter(([wasLoggedIn, isLoggedIn]) => !wasLoggedIn && isLoggedIn),
        switchMap(() => this.stateService.getInitialState('', 'products').pipe(take(1)))
      )
    ).subscribe((products) => {
      dispatch(new InitShopProductsAction(products));
    });

    // Update products from server on entry update (name, attribute, instock, reservations)
    this.actions$.pipe(
      ofActionSuccessful(UpdateSectionEntryFromSyncAction),
      filter(action => {
        const actions = ['cartTitle', 'cartPrice', 'cartAttributes'];
        const prop = action.path.split('/').pop();
        return actions.indexOf(prop) > -1;
      }),
      switchMap(() => this.stateService.getInitialState('', 'products', true).pipe(take(1)))

    ).subscribe((products) => {
      dispatch(new InitShopProductsAction(products));
    });
  }
开发者ID:berta-cms,项目名称:berta,代码行数:27,代码来源:shop-products.state.ts

示例3: addLoadingCount

  function addLoadingCount(count$: Observable<number>) {
    count$
      .pipe(
        distinctUntilChanged(),

        tap(count => {
          if (count < 0) {
            throw new Error(
              'Observables passed to loadingCount.add() must only emit positive numbers'
            );
          }
        }),

        // use takeUntil() so that we can finish each stream on stop() the same way we do when they complete,
        // by removing the previous count from the total
        takeUntil(stop$),
        endWith(0),
        startWith(0),
        pairwise(),
        map(([prev, next]) => next - prev)
      )
      .subscribe({
        next: delta => {
          loadingCount$.next(loadingCount$.getValue() + delta);
        },
        error: error => {
          if (fatalErrors) {
            fatalErrors.add(error);
          }
        },
      });
  }
开发者ID:elastic,项目名称:kibana,代码行数:32,代码来源:http_setup.ts

示例4: pairwise1

 pairwise1() {
   // Returns: [0,1], [1,2], [2,3], [3,4], [4,5]
   interval(1000)
     .pipe(
       pairwise(),
       take(5)
     )
     .subscribe(console.log);
 }
开发者ID:zwvista,项目名称:SampleMisc,代码行数:9,代码来源:combining.service.ts

示例5: shouldRestore

 shouldRestore(): Observable<boolean> {
   return this.router.events
     .pipe(
       startWith(null),
       filter(event => event === null || event instanceof NavigationEnd),
       pairwise(),
       map(([prev, current]: [NavigationEnd, NavigationEnd]) => this.pageChanged(prev, current)),
       filter(res => !!res),
     );
 }
开发者ID:kevinheader,项目名称:nebular,代码行数:10,代码来源:restore-scroll-top.service.ts

示例6: ngxsOnInit

 ngxsOnInit({ dispatch }: StateContext<ShopRegionalCostsModel>) {
   return concat(
     this.stateService.getInitialState('', 'regionalCosts').pipe(take(1)),
     /* LOGIN: */
     this.store$.select(UserState.isLoggedIn).pipe(
       pairwise(),
       filter(([wasLoggedIn, isLoggedIn]) => !wasLoggedIn && isLoggedIn),
       switchMap(() => this.stateService.getInitialState('', 'regionalCosts').pipe(take(1)))
     )
   ).subscribe((regionalCosts) => {
     dispatch(new InitShopRegionalCostsAction(regionalCosts));
   });
 }
开发者ID:berta-cms,项目名称:berta,代码行数:13,代码来源:shop-regional-costs.state.ts

示例7: updatePlaybackRate

/**
 * Manage playback speed.
 * Set playback rate set by the user, pause playback when the player appear to
 * stall and restore the speed once it appears to un-stall.
 *
 * @param {HTMLMediaElement} mediaElement
 * @param {Observable} speed$ - emit speed set by the user
 * @param {Observable} clock$
 * @param {Object} options - Contains the following properties:
 *   - pauseWhenStalled {Boolean|undefined} - true if the player
 *     stalling should lead to a pause until it un-stalls. True by default.
 * @returns {Observable}
 */
export default function updatePlaybackRate(
  mediaElement : HTMLMediaElement,
  speed$ : Observable<number>,
  clock$ : Observable<IInitClockTick>,
  { pauseWhenStalled = true } : IPlaybackRateOptions
) : Observable<number> {
  let forcePause$ : Observable<boolean>;

  if (!pauseWhenStalled) {
    forcePause$ = observableOf(false);
  } else {
    const lastTwoTicks$ : Observable<[IInitClockTick, IInitClockTick]> =
      clock$.pipe(pairwise());

    forcePause$ = lastTwoTicks$
      .pipe(
        map(([prevTiming, timing]) => {
          const isStalled = timing.stalled;
          const wasStalled = prevTiming.stalled;
          if (
            !wasStalled !== !isStalled || // xor
            (wasStalled && isStalled && wasStalled.reason !== isStalled.reason)
          ) {
            return !wasStalled;
          }
        }),
        filter((val : boolean|undefined) : val is boolean => val != null),
        startWith(false)
      );
  }

  return forcePause$
    .pipe(switchMap(shouldForcePause => {
      if (shouldForcePause) {
        return observableDefer(() => {
          log.info("Init: Pause playback to build buffer");
          mediaElement.playbackRate = 0;
          return observableOf(0);
        });
      }
      return speed$
        .pipe(tap((speed) => {
          log.info("Init: Resume playback speed", speed);
          mediaElement.playbackRate = speed;
        }));
    }));
}
开发者ID:canalplus,项目名称:rx-player,代码行数:60,代码来源:update_playback_rate.ts

示例8: ngxsOnInit

  ngxsOnInit({ dispatch }: StateContext<ShopSettingsModel>) {
    return concat(
      this.stateService.getInitialState('', 'settings').pipe(take(1)),
      /* LOGIN: */
      this.store$.select(UserState.isLoggedIn).pipe(
        pairwise(),
        filter(([wasLoggedIn, isLoggedIn]) => !wasLoggedIn && isLoggedIn),
        switchMap(() => this.stateService.getInitialState('', 'settings').pipe(take(1)))
      )
    ).subscribe((settings) => {
      const newState: {[k: string]: any} = {};

      for (const siteSlug in settings) {
        newState[siteSlug] = this.initializeShopSettingsForSite(settings[siteSlug]);
      }

      dispatch(new InitShopSettingsAction(newState));
    });
  }
开发者ID:berta-cms,项目名称:berta,代码行数:19,代码来源:shop-settings.state.ts

示例9: ngxsOnInit

  ngxsOnInit({ dispatch }: StateContext<ShopSettingsConfigModel>) {
    return concat(
      this.stateService.getInitialState('', 'settingsConfig').pipe(take(1)),
      /* LOGIN: */
      this.store$.select(UserState.isLoggedIn).pipe(
        pairwise(),
        filter(([wasLoggedIn, isLoggedIn]) => !wasLoggedIn && isLoggedIn),
        switchMap(() => this.stateService.getInitialState('', 'settingsConfig').pipe(take(1)))
      )
    ).subscribe((settingsConfig) => {
      const settingGroups = {};

      for (const groupSlug in settingsConfig) {
        settingGroups[groupSlug] = initSettingConfigGroup(settingsConfig[groupSlug]);
        delete settingGroups[groupSlug][groupSlug];
      }

      dispatch(new InitShopSettingsConfigAction(settingGroups));
    });
  }
开发者ID:berta-cms,项目名称:berta,代码行数:20,代码来源:shop-settings-config.state.ts

示例10: ngxsOnInit

  ngxsOnInit({ dispatch }: StateContext<SiteSettingsConfigStateModel>) {
    concat(
      this.appStateService.getInitialState('', 'siteSettingsConfig').pipe(take(1)),
      this.actions$.pipe(ofActionSuccessful(UserLoginAction), switchMap(() => {
        return this.appStateService.getInitialState('', 'siteSettingsConfig').pipe(take(1));
      }))
    )
    .subscribe({
      next: (siteSettingsConfig: SiteSettingsConfigResponse) => {
        dispatch(new InitSiteSettingsConfigAction(siteSettingsConfig));
      },
      error: (error) => console.error(error)
    });

    // Listen for language change
    this.store.select(SiteSettingsState.getCurrentSiteLanguage).pipe(
      pairwise(),
      filter(([prevLang, lang]) => !!prevLang && !!lang && prevLang !== lang),
      switchMap(([, language]) => this.appStateService.getLocaleSettings(language, 'siteSettingsConfig').pipe(take(1)))
    ).subscribe((siteSettingsConfig: SiteSettingsConfigResponse) => {
      dispatch(new InitSiteSettingsConfigAction(siteSettingsConfig));
    });
  }
开发者ID:berta-cms,项目名称:berta,代码行数:23,代码来源:site-settings-config.state.ts


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