本文整理匯總了TypeScript中rxjs/operators.bufferWhen函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript bufferWhen函數的具體用法?TypeScript bufferWhen怎麽用?TypeScript bufferWhen使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了bufferWhen函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should not break unsubscription chains when result is unsubscribed explicitly', () => {
const e1 = hot('--a--^---b---c---d---e---f---g---h------| ');
const subs = '^ ! ';
const closings = [
cold( '---------------(s|) '),
cold( '----------(s|) '),
cold( '-------------(s|)')];
const closeSubs = ['^ ! ',
' ^ ! '];
const expected = '---------------x--- ';
const unsub = ' ! ';
const values = {
x: ['b', 'c', 'd']
};
let i = 0;
const result = e1.pipe(
mergeMap((x: any) => of(x)),
bufferWhen(() => closings[i++]),
mergeMap((x: any) => of(x))
);
expectObservable(result, unsub).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(subs);
expectSubscriptions(closings[0].subscriptions).toBe(closeSubs[0]);
expectSubscriptions(closings[1].subscriptions).toBe(closeSubs[1]);
expectSubscriptions(closings[2].subscriptions).toBe([]);
});
示例2: interval
observable1 = constructorZone1.run(() => {
const source = interval(100);
return source.pipe(bufferWhen(() => {
expect(Zone.current.name).toEqual(constructorZone1.name);
return interval(220);
}));
});
示例3: bufferWhen1
bufferWhen1() {
// emit value every 1 second
const oneSecondInterval = interval(1000);
// return an observable that emits value every 5 seconds
const fiveSecondInterval = () => interval(5000);
// every five seconds, emit buffered values
const bufferWhenExample = oneSecondInterval.pipe(bufferWhen(fiveSecondInterval));
// log values
// ex. output: [0,1,2,3]...[4,5,6,7,8]
const subscribe = bufferWhenExample.subscribe(val =>
console.log('Emitted Buffer: ', val)
);
}
示例4: asDiagram
asDiagram('bufferWhen')('should emit buffers that close and reopen', () => {
const e1 = hot('--a--^---b---c---d---e---f---g---------|');
const e2 = cold( '--------------(s|)');
// --------------(s|)
const expected = '--------------x-------------y-----(z|)';
const values = {
x: ['b', 'c', 'd'],
y: ['e', 'f', 'g'],
z: [] as string[]
};
expectObservable(e1.pipe(bufferWhen(() => e2))).toBe(expected, values);
});