本文整理汇总了TypeScript中rxjs/operators.sample函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sample函数的具体用法?TypeScript sample怎么用?TypeScript sample使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sample函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: sample1
sample1() {
// emit value every 1s
const source = interval(1000);
// sample last emitted value from source every 2s
const example = source.pipe(sample(interval(2000)));
// output: 2..4..6..8..
const subscribe = example.subscribe(val => console.log(val));
}
示例2: sample3
sample3() {
const listener = merge(
fromEvent(document, 'mousedown').pipe(mapTo(false)),
fromEvent(document, 'mousemove').pipe(mapTo(true))
)
.pipe(sample(fromEvent(document, 'mouseup')))
.subscribe(isDragging => {
console.log('Were you dragging?', isDragging);
});
}
示例3: asDiagram
asDiagram('sample')('should get samples when the notifier emits', () => {
const e1 = hot('---a----b---c----------d-----| ');
const e1subs = '^ ! ';
const e2 = hot('-----x----------x---x------x---|');
const e2subs = '^ ! ';
const expected = '-----a----------c----------d-| ';
expectObservable(e1.pipe(sample(e2))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});
示例4: it
it('should complete only when the source completes, if notifier completes early', () => {
const e1 = hot('----a----b----c----d----e----f---|');
const e1subs = '^ !';
const e2 = hot('------x-| ');
const e2subs = '^ ! ';
const expected = '------a--------------------------|';
expectObservable(e1.pipe(sample(e2))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});