本文整理匯總了TypeScript中rxjs/operators.combineAll函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript combineAll函數的具體用法?TypeScript combineAll怎麽用?TypeScript combineAll使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了combineAll函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: combineAll1
combineAll1() {
// emit every 1s, take 2
const source = interval(1000).pipe(take(2));
// map each emitted value from source to interval observable that takes 5 values
const example = source.pipe(
map(val => interval(1000).pipe(map(i => `Result (${val}): ${i}`), take(5)))
);
/*
2 values from source will map to 2 (inner) interval observables that emit every 1s
combineAll uses combineLatest strategy, emitting the last value from each
whenever either observable emits a value
*/
const combined = example.pipe(combineAll());
/*
output:
["Result (0): 0", "Result (1): 0"]
["Result (0): 1", "Result (1): 0"]
["Result (0): 1", "Result (1): 1"]
["Result (0): 2", "Result (1): 1"]
["Result (0): 2", "Result (1): 2"]
["Result (0): 3", "Result (1): 2"]
["Result (0): 3", "Result (1): 3"]
["Result (0): 4", "Result (1): 3"]
["Result (0): 4", "Result (1): 4"]
*/
const subscribe = combined.subscribe(val => console.log(val));
}
示例2: of
observable1 = constructorZone1.run(() => {
const source = of(1, 2);
const highOrder = source.pipe(map((src: any) => {
expect(Zone.current.name).toEqual(constructorZone1.name);
return of(src);
}));
return highOrder.pipe(combineAll());
});
示例3: it
it('should infer correctly with the projector', () => {
const o = of([1, 2, 3]).pipe(combineAll((values: number) => ['x', 'y', 'z'])); // $ExpectType Observable<string[]>
});
示例4: higherOrder
export function combineAll<T, R>(this: Observable<ObservableInput<T>>, project?: (...values: Array<T>) => R): Observable<R> {
return higherOrder(project)(this);
}