本文整理汇总了TypeScript中rxjs/operators.windowTime函数的典型用法代码示例。如果您正苦于以下问题:TypeScript windowTime函数的具体用法?TypeScript windowTime怎么用?TypeScript windowTime使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了windowTime函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: windowTime1
windowTime1() {
// emit immediately then every 1s
const source = timer(0, 1000);
const example = source.pipe(
// start new window every 3s
windowTime(3000),
tap(_ => console.log('NEW WINDOW!'))
);
const subscribeTwo = example
.pipe(
// window emits nested observable
mergeAll()
/*
output:
"NEW WINDOW!"
0
1
2
"NEW WINDOW!"
3
4
5
*/
)
.subscribe(val => console.log(val));
}
示例2: if
export function windowTime<T>(this: Observable<T>,
windowTimeSpan: number): Observable<Observable<T>> {
let scheduler: SchedulerLike = asyncScheduler;
let windowCreationInterval: number = null;
let maxWindowSize: number = Number.POSITIVE_INFINITY;
if (isScheduler(arguments[3])) {
scheduler = arguments[3];
}
if (isScheduler(arguments[2])) {
scheduler = arguments[2];
} else if (isNumeric(arguments[2])) {
maxWindowSize = arguments[2];
}
if (isScheduler(arguments[1])) {
scheduler = arguments[1];
} else if (isNumeric(arguments[1])) {
windowCreationInterval = arguments[1];
}
return higherOrder(windowTimeSpan, windowCreationInterval, maxWindowSize, scheduler)(this) as Observable<Observable<T>>;
}
示例3: it
it('should emit an error-only window if outer is a simple throw-Observable', () => {
const source = cold('#');
const subs = '(^!)';
const expected = '(w#)';
const w = cold('#');
const expectedValues = { w };
const timeSpan = time('-----|');
const interval = time('----------|');
const result = source.pipe(windowTime(timeSpan, interval, rxTestScheduler));
expectObservable(result).toBe(expected, expectedValues);
expectSubscriptions(source.subscriptions).toBe(subs);
});
示例4: hot
'windowCreationInterval', () => {
const source = hot('--1--2--^-a--b--c--de-f---g--h--i-|');
const subs = '^ !';
// 100 frames 0---------1---------2-----|
// 50 ----|
// 50 ----|
// 50 ----|
const expected = 'x---------y---------z-----|';
const x = cold( '--a--(b|) ');
const y = cold( '-de-(f|) ');
const z = cold( '-h--i| ');
const values = { x, y, z };
const result = source.pipe(windowTime(50, 100, 3, rxTestScheduler));
expectObservable(result).toBe(expected, values);
expectSubscriptions(source.subscriptions).toBe(subs);
});
示例5: window1
window1() {
// emit immediately then every 1s
const source = timer(0, 1000);
const example = source.pipe(windowTime(3000));
const count = example.pipe(scan((acc: number, curr: any) => acc + 1, 0));
/*
"Window 1:"
0
1
2
"Window 2:"
3
4
5
...
*/
const subscribe = count.subscribe(val => console.log(`Window ${val}:`));
const subscribeTwo = example
.pipe(mergeAll())
.subscribe(val => console.log(val));
}