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