本文整理汇总了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;
};