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