本文整理汇总了TypeScript中rxjs/operators.bufferToggle函数的典型用法代码示例。如果您正苦于以下问题:TypeScript bufferToggle函数的具体用法?TypeScript bufferToggle怎么用?TypeScript bufferToggle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bufferToggle函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should emit buffers using constying cold closings', () => {
const e1 = hot('--a--^---b---c---d---e---f---g---h------| ');
const e2 = cold('--x-----------y--------z---| ');
const subs = '^ ! ';
const closings = [
cold( '---------------s--| '),
cold( '----(s|) '),
cold( '---------------(s|)')];
const closeSubs = [' ^ ! ',
' ^ ! ',
' ^ ! '];
const expected = '-----------------ij----------------(k|) ';
const values = {
i: ['b', 'c', 'd', 'e'],
j: ['e'],
k: ['g', 'h']
};
let i = 0;
const result = e1.pipe(bufferToggle(e2, () => closings[i++]));
expectObservable(result).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(closeSubs[2]);
});
示例2: interval
observable1 = constructorZone1.run(() => {
const source = interval(10);
const opening = interval(25);
const closingSelector = (v: any) => {
expect(Zone.current.name).toEqual(constructorZone1.name);
return v % 2 === 0 ? of(v) : empty();
};
return source.pipe(bufferToggle(opening, closingSelector));
});
示例3: it
it('should handle empty source', () => {
const e1 = cold('|');
const e2 = cold('--o-----|');
const e3 = cold( '-----c--|');
const expected = '|';
const values = { x: [] as string[] };
const result = e1.pipe(bufferToggle(e2, () => e3));
expectObservable(result).toBe(expected, values);
});