本文整理匯總了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);
示例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));
});
}
示例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);
}
},
});
}
示例4: pairwise1
pairwise1() {
// Returns: [0,1], [1,2], [2,3], [3,4], [4,5]
interval(1000)
.pipe(
pairwise(),
take(5)
)
.subscribe(console.log);
}
示例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),
);
}
示例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));
});
}
示例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;
}));
}));
}
示例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));
});
}
示例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));
});
}
示例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));
});
}