本文整理匯總了TypeScript中rxjs/operators.buffer函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript buffer函數的具體用法?TypeScript buffer怎麽用?TypeScript buffer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了buffer函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: asDiagram
asDiagram('buffer')('should emit buffers that close and reopen', () => {
const a = hot('-a-b-c-d-e-f-g-h-i-|');
const b = hot('-----B-----B-----B-|');
const expected = '-----x-----y-----z-|';
const expectedValues = {
x: ['a', 'b', 'c'],
y: ['d', 'e', 'f'],
z: ['g', 'h', 'i']
};
expectObservable(a.pipe(buffer(b))).toBe(expected, expectedValues);
});
示例2: it
it('should unsubscribe notifier when source unsubscribed', () => {
const a = hot('-a-b-c-d-e-f-g-h-i-|');
const b = hot('-----1-----2-----3-|');
const bsubs = '^ !';
const expected = '-----(x|)';
const expectedValues = {
x: ['a', 'b', 'c'],
};
expectObservable(a.pipe(buffer(b), take(1))).toBe(expected, expectedValues);
expectSubscriptions(b.subscriptions).toBe(bsubs);
});
示例3: buffer1
buffer1() {
// Create an observable that emits a value every second
const myInterval = interval(1000);
// Create an observable that emits every time document is clicked
const bufferBy = fromEvent(document, 'click');
/*
Collect all values emitted by our interval observable until we click document.
This will cause the bufferBy Observable to emit a value, satisfying the buffer.
Pass us all collected values since last buffer as an array.
*/
const myBufferedInterval = myInterval.pipe(buffer(bufferBy));
// Print values to console
// ex. output: [1,2,3] ... [4,5,6,7,8]
const subscribe = myBufferedInterval.subscribe(val =>
console.log(' Buffered Values:', val)
);
}