本文整理匯總了TypeScript中rxjs/operators.switchMapTo函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript switchMapTo函數的具體用法?TypeScript switchMapTo怎麽用?TypeScript switchMapTo使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了switchMapTo函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should switch to an inner cold observable, outer eventually throws', () => {
const x = cold( '--a--b--c--d--e--|');
const xsubs = ' ^ ! ';
const e1 = hot('---------x---------# ');
const e1subs = '^ ! ';
const expected = '-----------a--b--c-# ';
expectObservable(e1.pipe(switchMapTo(x))).toBe(expected);
expectSubscriptions(x.subscriptions).toBe(xsubs);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
示例2: it
it('should switch to an inner that just raises an error', () => {
const x = cold('#');
const xsubs = ' (^!) ';
const e1 = hot('---------x---------x---------|');
const e1subs = '^ ! ';
const expected = '---------# ';
expectObservable(e1.pipe(switchMapTo(x))).toBe(expected);
expectSubscriptions(x.subscriptions).toBe(xsubs);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
示例3: 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-xx-x-x---|';
const values = {x: 10};
const result = e1.pipe(switchMapTo(e2));
expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
示例4: ActivatedWith
export const activatorDropTarget = (dnd: SkyhookDndService, types: Types, waitMillis: number, spec: ActivatorSpec) => {
const dt = dnd.dropTarget(types, {
...spec as DropTargetSpec,
hover: monitor => {
hoverSubject$.next(new ActivatedWith(monitor.getItemType(), monitor.getItem()));
spec.hover && spec.hover(monitor);
}
});
const startedHovering$ = dt
.listen(m => m.isOver() && m.canDrop())
.pipe(
// just emit when it changes to not-isOver
distinctUntilChanged(),
filter(isOver => isOver),
// tap(() => console.log('started (isOver)'))
);
const stoppedHovering$ = dt
.listen(m => m.isOver())
.pipe(
// just emit when it changes to not-canDrop
distinctUntilChanged(),
filter(canDrop => canDrop === false),
// tap(() => console.log('stoppedHovering (canDrop)'))
);
// hover events input stream
const hoverSubject$ = new Subject<ActivatedWith>();
const activations$: Observable<ActivatedWith> = startedHovering$.pipe(
// tap(() => console.log('startedHovering -> switchMapTo(...)')),
switchMapTo(
hoverSubject$.pipe(
delay(waitMillis),
takeUntil(stoppedHovering$),
take(1),
)
),
);
// internal subscription should die when the connection is torn down
let subsc = activations$.subscribe(spec.onActivate);
dt.add(subsc);
return dt;
};