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