本文整理匯總了TypeScript中rxjs/operators.sampleTime函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript sampleTime函數的具體用法?TypeScript sampleTime怎麽用?TypeScript sampleTime使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了sampleTime函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: sampleObservable
export function sampleObservable(obs: Observable<any>, scheduler?: any) {
return obs.pipe(
sampleTime(100, scheduler),
share(),
startWith('')
);
}
示例2: it
it('should completes if source does not emits', () => {
const e1 = cold('|');
const e1subs = '(^!)';
const expected = '|';
expectObservable(e1.pipe(sampleTime(60, rxTestScheduler))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
示例3: asDiagram
asDiagram('sampleTime(70)')('should get samples on a delay', () => {
const e1 = hot('a---b-c---------d--e---f-g-h--|');
const e1subs = '^ !';
const expected = '-------c-------------e------h-|';
// timer -------!------!------!------!--
expectObservable(e1.pipe(sampleTime(70, rxTestScheduler))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
示例4: _updateUpdateRateObservable
private _updateUpdateRateObservable(item: IoSourceItems) {
const [source, , updateRate, association, updateSubject, updateSubscription] = item;
// Unsubscribe and discard already scheduled IO values
updateSubscription && updateSubscription.unsubscribe();
if (!association.value) {
item[5] = undefined;
return;
}
const rate = updateRate.value;
let updateObs: Observable<any>;
if (rate === undefined || rate === 0) {
updateObs = updateSubject;
} else {
switch (source.updateStrategy || IoSourceBackpressureStrategy.Default) {
case IoSourceBackpressureStrategy.Default:
case IoSourceBackpressureStrategy.Sample:
updateObs = updateSubject.pipe(sampleTime(rate));
break;
case IoSourceBackpressureStrategy.Throttle:
updateObs = updateSubject.pipe(debounceTime(rate));
break;
case IoSourceBackpressureStrategy.None:
updateObs = updateSubject;
break;
default:
updateObs = updateSubject;
break;
}
}
item[5] = updateObs.subscribe(value =>
this.communicationManager.publishIoValue(source, value));
}