本文整理汇总了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));
}