本文整理汇总了TypeScript中rxjs/operators.windowToggle函数的典型用法代码示例。如果您正苦于以下问题:TypeScript windowToggle函数的具体用法?TypeScript windowToggle怎么用?TypeScript windowToggle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了windowToggle函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: hot
() => {
const e1 = hot('--1--2--^--a--b--c--d--e--f--g--h--|');
const e1subs = '^ !';
const e2 = cold( '--------x-------x-------x--|');
const e2subs = '^ !';
const e3 = cold( '----------(x|) ');
// ----------(x|)
// ----------(x|)
const e3subs = [ ' ^ ! ', // eslint-disable-line array-bracket-spacing
' ^ ! ',
' ^ !'];
const expected = '--------x-------y-------z--|';
const x = cold( '-c--d--e--(f|) ');
const y = cold( '--f--g--h-| ');
const z = cold( '---|');
const values = { x, y, z };
const source = e1.pipe(windowToggle(e2, (value: string) => {
expect(value).to.equal('x');
return e3;
}));
expectObservable(source).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
expectSubscriptions(e3.subscriptions).toBe(e3subs);
});
示例2: it
it('should not break unsubscription chains when result is unsubscribed explicitly', () => {
const e1 = hot('--a--^---b---c---d---e---f---g---h------| ');
const e1subs = '^ ! ';
const e2 = cold('--x-----------y--------z---| ');
const e2subs = '^ ! ';
const close = [cold( '---------------s--| '),
cold( '----(s|) '),
cold( '---------------(s|)')];
const closeSubs = [' ^ ! ',
' ^! '];
const expected = '--x-----------y- ';
const x = cold( '--b---c---d--- ');
const y = cold( '-- ');
const unsub = ' ! ';
const values = { x, y };
let i = 0;
const result = e1
.mergeMap((x: string) => of(x))
.pipe(windowToggle(e2, () => close[i++]))
.mergeMap(x => of(x));
expectObservable(result, unsub).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
expectSubscriptions(close[0].subscriptions).toBe(closeSubs[0]);
expectSubscriptions(close[1].subscriptions).toBe(closeSubs[1]);
});
示例3: windowToggle1
windowToggle1() {
// emit immediately then every 1s
const source = timer(0, 1000);
// toggle window on every 5
const toggle = interval(5000);
const example = source.pipe(
// turn window on every 5s
windowToggle(toggle, val => interval(val * 1000)),
tap(_ => console.log('NEW WINDOW!'))
);
const subscribeTwo = example
.pipe(
// window emits nested observable
mergeAll()
/*
output:
"NEW WINDOW!"
5
"NEW WINDOW!"
10
11
"NEW WINDOW!"
15
16
"NEW WINDOW!"
20
21
22
*/
)
.subscribe(val => console.log(val));
}