当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript operators.switchMapTo函数代码示例

本文整理汇总了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);
  });
开发者ID:DallanQ,项目名称:rxjs,代码行数:11,代码来源:switchMapTo-spec.ts

示例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);
  });
开发者ID:deanius,项目名称:RxJS,代码行数:11,代码来源:switchMapTo-spec.ts

示例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);
  });
开发者ID:DallanQ,项目名称:rxjs,代码行数:12,代码来源:switchMapTo-spec.ts

示例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;
};
开发者ID:fossabot,项目名称:angular-skyhook,代码行数:47,代码来源:activatorDropTarget.ts


注:本文中的rxjs/operators.switchMapTo函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。