本文整理匯總了TypeScript中rxjs/operators.concatMapTo函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript concatMapTo函數的具體用法?TypeScript concatMapTo怎麽用?TypeScript concatMapTo使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了concatMapTo函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should support the deprecated resultSelector', () => {
const results: Array<number[]> = [];
of(1, 2, 3).pipe(
concatMapTo(
of(4, 5, 6),
(a, b, i, ii) => [a, b, i, ii]
)
)
.subscribe({
next (value) {
results.push(value);
},
error(err) {
throw err;
},
complete() {
expect(results).to.deep.equal([
[1, 4, 0, 0],
[1, 5, 0, 1],
[1, 6, 0, 2],
[2, 4, 1, 0],
[2, 5, 1, 1],
[2, 6, 1, 2],
[3, 4, 2, 0],
[3, 5, 2, 1],
[3, 6, 2, 2],
]);
}
});
});
示例2: concatMapTo2
concatMapTo2() {
// emit value every 2 seconds
const interval$ = interval(2000);
// emit value every second for 5 seconds
const source = interval(1000).pipe(take(5));
/*
***Be Careful***: In situations like this where the source emits at a faster pace
than the inner observable completes, memory issues can arise.
(interval emits every 1 second, basicTimer completes every 5)
*/
// basicTimer will complete after 5 seconds, emitting 0,1,2,3,4
const example = interval$.pipe(
concatMapTo(
source,
(firstInterval, secondInterval) => `${firstInterval} ${secondInterval}`
)
);
/*
output: 0 0
0 1
0 2
0 3
0 4
1 0
1 1
continued...
*/
const subscribe = example.subscribe(val => console.log(val));
}
示例3: concatMapTo1
concatMapTo1() {
// emit value every 2 seconds
const sampleInterval = interval(500).pipe(take(5));
const fakeRequest = of('Network request complete').pipe(delay(3000));
// wait for first to complete before next is subscribed
const example = sampleInterval.pipe(concatMapTo(fakeRequest));
// result
// output: Network request complete...3s...Network request complete'
const subscribe = example.subscribe(val => console.log(val));
}
示例4: hot
('should map-and-flatten each item to an Observable', () => {
const e1 = hot('--1-----3--5-------|');
const e1subs = '^ !';
const e2 = cold('x-x-x| ', {x: 10});
const expected = '--x-x-x-x-x-xx-x-x-|';
const values = {x: 10};
const result = e1.pipe(concatMapTo(e2));
expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});