當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。