本文整理汇总了TypeScript中rxjs/operators.mergeMapTo函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mergeMapTo函数的具体用法?TypeScript mergeMapTo怎么用?TypeScript mergeMapTo使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mergeMapTo函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should not break unsubscription chains when result is unsubscribed explicitly', () => {
const source = cold('-1-2-3----4-|');
const sourceSubs = '^ ! ';
const multicasted = source.pipe(
mergeMap((x) => of(x)),
multicast(() => new Subject<string>())
) as ConnectableObservable<string>;
const subscriber1 = hot('a| ').pipe(mergeMapTo(multicasted));
const expected1 = '-1-2-3---- ';
const subscriber2 = hot(' b| ').pipe(mergeMapTo(multicasted));
const expected2 = ' -3---- ';
const subscriber3 = hot(' c| ').pipe(mergeMapTo(multicasted));
const expected3 = ' -- ';
const unsub = ' u ';
expectObservable(subscriber1).toBe(expected1);
expectObservable(subscriber2).toBe(expected2);
expectObservable(subscriber3).toBe(expected3);
expectSubscriptions(source.subscriptions).toBe(sourceSubs);
// Set up unsubscription action
let connection: Subscription;
expectObservable(hot(unsub).pipe(tap(() => {
connection.unsubscribe();
}))).toBe(unsub);
connection = multicasted.connect();
});
示例2: type
type('should support type signatures', () => {
let o: Observable<number>;
let m: Observable<string>;
/* tslint:disable:no-unused-variable */
let a1: Observable<string> = o.pipe(mergeMapTo(m));
let a2: Observable<string> = o.pipe(mergeMapTo(m, 3));
/* tslint:enable:no-unused-variable */
});
示例3: it
it('should disconnect when last subscriber unsubscribes', () => {
const source = cold( '-1-2-3----4-|');
const sourceSubs = ' ^ ! ';
const shared = source.pipe(share());
const subscriber1 = hot(' a| ').pipe(mergeMapTo(shared));
const unsub1 = ' ! ';
const expected1 = ' -1-2-3-- ';
const subscriber2 = hot(' b| ').pipe(mergeMapTo(shared));
const unsub2 = ' ! ';
const expected2 = ' -3---- ';
expectObservable(subscriber1, unsub1).toBe(expected1);
expectObservable(subscriber2, unsub2).toBe(expected2);
expectSubscriptions(source.subscriptions).toBe(sourceSubs);
});
示例4: it
it('should support the deprecated resultSelector', () => {
const results: Array<number[]> = [];
of(1, 2, 3).pipe(
mergeMapTo(
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],
]);
}
});
});
示例5: cold
'but is unsubscribed explicitly and early', () => {
const source = cold('-1-2-3----4-|');
const sourceSubs = '^ ! ';
const shared = source.pipe(share());
const unsub = ' ! ';
const subscriber1 = hot('a| ').pipe(mergeMapTo(shared));
const expected1 = '-1-2-3---- ';
const subscriber2 = hot(' b| ').pipe(mergeMapTo(shared));
const expected2 = ' -3---- ';
const subscriber3 = hot(' c| ').pipe(mergeMapTo(shared));
const expected3 = ' -- ';
expectObservable(subscriber1, unsub).toBe(expected1);
expectObservable(subscriber2, unsub).toBe(expected2);
expectObservable(subscriber3, unsub).toBe(expected3);
expectSubscriptions(source.subscriptions).toBe(sourceSubs);
});