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