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