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


TypeScript operators.withLatestFrom函数代码示例

本文整理汇总了TypeScript中rxjs/operators.withLatestFrom函数的典型用法代码示例。如果您正苦于以下问题:TypeScript withLatestFrom函数的具体用法?TypeScript withLatestFrom怎么用?TypeScript withLatestFrom使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了withLatestFrom函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: map

export const ngbFocusTrap = (element: HTMLElement, stopFocusTrap$: Observable<any>, refocusOnClick = false) => {
  // last focused element
  const lastFocusedElement$ =
      fromEvent<FocusEvent>(element, 'focusin').pipe(takeUntil(stopFocusTrap$), map(e => e.target));

  // 'tab' / 'shift+tab' stream
  fromEvent<KeyboardEvent>(element, 'keydown')
      .pipe(
          takeUntil(stopFocusTrap$),
          // tslint:disable:deprecation
          filter(e => e.which === Key.Tab),
          // tslint:enable:deprecation
          withLatestFrom(lastFocusedElement$))
      .subscribe(([tabEvent, focusedElement]) => {
        const[first, last] = getFocusableBoundaryElements(element);

        if ((focusedElement === first || focusedElement === element) && tabEvent.shiftKey) {
          last.focus();
          tabEvent.preventDefault();
        }

        if (focusedElement === last && !tabEvent.shiftKey) {
          first.focus();
          tabEvent.preventDefault();
        }
      });

  // inside click
  if (refocusOnClick) {
    fromEvent(element, 'click')
        .pipe(takeUntil(stopFocusTrap$), withLatestFrom(lastFocusedElement$), map(arr => arr[1] as HTMLElement))
        .subscribe(lastFocusedElement => lastFocusedElement.focus());
  }
};
开发者ID:ExFlo,项目名称:ng-boostrap,代码行数:34,代码来源:focus-trap.ts

示例2: map

> => (action$, state$, { selectLogFilterQueryAsJson, selectVisibleLogSummary }) => {
  const filterQuery$ = state$.pipe(map(selectLogFilterQueryAsJson));
  const summaryInterval$ = state$.pipe(
    map(selectVisibleLogSummary),
    map(({ start, end }) => (start && end ? getLoadParameters(start, end) : null)),
    filter(isNotNull)
  );

  const shouldLoadBetweenNewInterval$ = action$.pipe(
    filter(logPositionActions.reportVisibleSummary.match),
    filter(
      ({ payload: { bucketsOnPage, pagesBeforeStart, pagesAfterEnd } }) =>
        bucketsOnPage < MINIMUM_BUCKETS_PER_PAGE ||
        pagesBeforeStart < MINIMUM_BUFFER_PAGES ||
        pagesAfterEnd < MINIMUM_BUFFER_PAGES
    ),
    map(({ payload: { start, end } }) => getLoadParameters(start, end))
  );

  const shouldLoadWithNewFilter$ = action$.pipe(
    filter(logFilterActions.applyLogFilterQuery.match),
    withLatestFrom(filterQuery$, (filterQuery, filterQueryString) => filterQueryString)
  );

  return merge(
    shouldLoadBetweenNewInterval$.pipe(
      withLatestFrom(filterQuery$),
      exhaustMap(([{ start, end, bucketSize }, filterQuery]) => [
        loadSummary({
          start,
          end,
          sourceId: 'default',
          bucketSize,
          filterQuery,
        }),
      ])
    ),
    shouldLoadWithNewFilter$.pipe(
      withLatestFrom(summaryInterval$),
      exhaustMap(([filterQuery, { start, end, bucketSize }]) => [
        loadSummary({
          start,
          end,
          sourceId: 'default',
          bucketSize: (end - start) / LOAD_BUCKETS_PER_PAGE,
          filterQuery,
        }),
      ])
    )
  );
};
开发者ID:gingerwizard,项目名称:kibana,代码行数:51,代码来源:epic.ts

示例3: it

  it('should not break unsubscription chains when result is unsubscribed explicitly', () => {
    const e1 =   hot('--a--^---b---c---d-|');
    const e1subs =        '^          !   ';
    const e2 =   hot('--e--^-f---g---h------|');
    const e2subs =        '^          !   ';
    const e3 =   hot('--i--^-j---k---l------|');
    const e3subs =        '^          !   ';
    const expected =      '----x---y---   ';
    const unsub =         '           !   ';
    const values = {
      x: 'bfj',
      y: 'cgk',
      z: 'dhl'
    };
    const project = function (a: string, b: string, c: string) { return a + b + c; };

    const result = e1.pipe(
      mergeMap((x: string) => of(x)),
      withLatestFrom(e2, e3, project),
      mergeMap((x: string) => of(x))
    );

    expectObservable(result, unsub).toBe(expected, values);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
    expectSubscriptions(e2.subscriptions).toBe(e2subs);
    expectSubscriptions(e3.subscriptions).toBe(e3subs);
  });
开发者ID:DallanQ,项目名称:rxjs,代码行数:27,代码来源:withLatestFrom-spec.ts

示例4: takeUntil2

  takeUntil2() {
    // emit value every 1s
    const source = interval(1000);
    // is number even?
    const isEven = val => val % 2 === 0;
    // only allow values that are even
    const evenSource = source.pipe(filter(isEven));
    // keep a running total of the number of even numbers out
    const evenNumberCount = evenSource.pipe(scan((acc, _) => acc + 1, 0));
    // do not emit until 5 even numbers have been emitted
    const fiveEvenNumbers = evenNumberCount.pipe(filter(val => val > 5));

    const example = evenSource.pipe(
      // also give me the current even number count for display
      withLatestFrom(evenNumberCount),
      map(([val, count]) => `Even number (${count}) : ${val}`),
      // when five even numbers have been emitted, complete source observable
      takeUntil(fiveEvenNumbers)
    );
    /*
    	Even number (1) : 0,
      Even number (2) : 2
    	Even number (3) : 4
    	Even number (4) : 6
    	Even number (5) : 8
    */
    const subscribe = example.subscribe(val => console.log(val));
  }
开发者ID:zwvista,项目名称:SampleMisc,代码行数:28,代码来源:conditional.service.ts

示例5: map

> => (
  action$,
  state$,
  { selectMetricTimeUpdatePolicyInterval, selectMetricRangeFromTimeRange }
) => {
  const updateInterval$ = state$.pipe(
    map(selectMetricTimeUpdatePolicyInterval),
    filter(isNotNull)
  );

  const range$ = state$.pipe(
    map(selectMetricRangeFromTimeRange),
    filter(isNotNull)
  );

  return action$.pipe(
    filter(startMetricsAutoReload.match),
    withLatestFrom(updateInterval$, range$),
    exhaustMap(([action, updateInterval, range]) =>
      timer(0, updateInterval).pipe(
        map(() =>
          setRangeTime({
            from: moment()
              .subtract(range, 'ms')
              .valueOf(),
            to: moment().valueOf(),
            interval: '1m',
          })
        ),
        takeUntil(action$.pipe(filter(stopMetricsAutoReload.match)))
      )
    )
  );
};
开发者ID:gingerwizard,项目名称:kibana,代码行数:34,代码来源:epic.ts

示例6: asDiagram

  asDiagram('withLatestFrom')('should combine events from cold observables', () => {
    const e1 =  cold('-a--b-----c-d-e-|');
    const e2 =  cold('--1--2-3-4---|   ');
    const expected = '----B-----C-D-E-|';

    const result = e1.pipe(withLatestFrom(e2, (a: string, b: string) => String(a) + String(b)));

    expectObservable(result).toBe(expected, { B: 'b1', C: 'c4', D: 'd4', E: 'e4' });
  });
开发者ID:DallanQ,项目名称:rxjs,代码行数:9,代码来源:withLatestFrom-spec.ts

示例7: withLatestFrom

export const createTimelineNoteEpic = <State>(): Epic<Action, Action, State> => action$ =>
  action$.pipe(
    withLatestFrom(),
    filter(([action]) => timelineNoteActionsType.includes(action.type)),
    switchMap(([action]) => {
      dispatcherTimelinePersistQueue.next({ action });
      return empty();
    })
  );
开发者ID:,项目名称:,代码行数:9,代码来源:

示例8: constructor

 constructor(initialState: T, action$: Dispatcher, reducer$: Reducer) {
   super(initialState);
   action$
     .pipe(
       observeOn(queue),
       withLatestFrom(reducer$),
       scan<[Action, ActionReducer<any>], T>(
         (state, [action, reducer]) => reducer(state, action),
         initialState,
       ),
     )
     .subscribe(value => this.next(value));
 }
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:13,代码来源:state.ts

示例9: editReducer

    .run(['ConfigEffects', 'ConfigureState', '$uiRouter', (ConfigEffects, ConfigureState, $uiRouter) => {
        $uiRouter.plugin(UIRouterRx);

        ConfigureState.addReducer(refsReducer({
            models: {at: 'domains', store: 'caches'},
            caches: {at: 'caches', store: 'models'}
        }));

        ConfigureState.addReducer((state, action) => Object.assign({}, state, {
            clusterConfiguration: editReducer(state.clusterConfiguration, action),
            configurationLoading: loadingReducer(state.configurationLoading, action),
            basicCaches: itemsEditReducerFactory(basicCachesActionTypes)(state.basicCaches, action),
            clusters: mapStoreReducerFactory(clustersActionTypes)(state.clusters, action),
            shortClusters: mapCacheReducerFactory(shortClustersActionTypes)(state.shortClusters, action),
            caches: mapStoreReducerFactory(cachesActionTypes)(state.caches, action),
            shortCaches: mapCacheReducerFactory(shortCachesActionTypes)(state.shortCaches, action),
            models: mapStoreReducerFactory(modelsActionTypes)(state.models, action),
            shortModels: mapCacheReducerFactory(shortModelsActionTypes)(state.shortModels, action),
            igfss: mapStoreReducerFactory(igfssActionTypes)(state.igfss, action),
            shortIgfss: mapCacheReducerFactory(shortIGFSsActionTypes)(state.shortIgfss, action),
            edit: editReducer2(state.edit, action)
        }));

        ConfigureState.addReducer(shortObjectsReducer);

        ConfigureState.addReducer((state, action) => {
            switch (action.type) {
                case 'APPLY_ACTIONS_UNDO':
                    return action.state;

                default:
                    return state;
            }
        });

        const la = ConfigureState.actions$.pipe(scan((acc, action) => [...acc, action], []));

        ConfigureState.actions$.pipe(
            filter((a) => a.type === 'UNDO_ACTIONS'),
            withLatestFrom(la, ({actions}, actionsWindow, initialState) => {
                return {
                    type: 'APPLY_ACTIONS_UNDO',
                    state: actionsWindow.filter((a) => !actions.includes(a)).reduce(ConfigureState._combinedReducer, {})
                };
            }),
            tap((a) => ConfigureState.dispatchAction(a))
        )
        .subscribe();
        ConfigEffects.connect();
    }])
开发者ID:gridgain,项目名称:gridgain,代码行数:50,代码来源:index.ts

示例10: onReadCompleted

 onReadCompleted(data: string) {
   this.app$.pipe(
     withLatestFrom(this.store.select(getQrCodeTemplates)),
   ).pipe(first()).subscribe(([ app, templates ]) => {
     // create the default qr template if there's not any
     if (!templates.some(template => template.is_default)) {
       const payload: DefaultQrCodeTemplatePayload = {
         appId: app.app_id,
         backendId: app.backend_server,
         data: data,
       };
       this.store.dispatch(new CreateDefaultQrCodeTemplateAction(payload));
     }
   });
 }
开发者ID:our-city-app,项目名称:plugin-mobicage-control-center,代码行数:15,代码来源:generate-images.component.ts

示例11: map

> => (action$, state$, { selectWaffleTimeUpdatePolicyInterval }) => {
  const updateInterval$ = state$.pipe(
    map(selectWaffleTimeUpdatePolicyInterval),
    filter(isNotNull)
  );

  return action$.pipe(
    filter(startAutoReload.match),
    withLatestFrom(updateInterval$),
    exhaustMap(([action, updateInterval]) =>
      timer(0, updateInterval).pipe(
        map(() => jumpToTime(Date.now())),
        takeUntil(action$.pipe(filter(stopAutoReload.match)))
      )
    )
  );
};
开发者ID:elastic,项目名称:kibana,代码行数:17,代码来源:epic.ts

示例12: ngOnInit

  ngOnInit() {
    const recallSubject$ = new Subject();
    this.time$ = this.store.select("clockReducer");
    this.people$ = this.store.select("peoplezReducer");

    this.person$ = new Subject();
    this.seconds$ = interval(1000);
    this.recall$ = recallSubject$
      .pipe(withLatestFrom(this.time$, (_, y) => y))
      .pipe(map(time => ({type: RECALL, payload: time})));

    this.merged$ = merge(
      this.seconds$.pipe(mapTo({type: SECOND, payload: 1})),
      this.person$.pipe(map(value => ({payload: value, type: ADVANCE}))),
      this.recall$
    );

  }
开发者ID:screenm0nkey,项目名称:angular2-examples-webpack,代码行数:18,代码来源:ngrx-people.component.ts

示例13: filter

> => (action$, state$, { apolloClient$ }) =>
  action$.pipe(
    filter(actionCreators.resolve.match),
    withLatestFrom(apolloClient$),
    switchMap(([{ payload: variables }, apolloClient]) =>
      from(
        apolloClient.query<Data>({
          query: graphqlQuery,
          variables,
          fetchPolicy: 'no-cache',
        })
      ).pipe(
        map(result => actionCreators.resolveDone({ params: variables, result })),
        catchError(error => [actionCreators.resolveFailed({ params: variables, error })]),
        startWith(actionCreators.resolveStarted(variables))
      )
    )
  );
开发者ID:salihkardan,项目名称:kibana,代码行数:18,代码来源:remote_graphql_state.ts

示例14: withLatestFrom

export const createMover = <T extends Historical>(
  card$: Observable<T>,
  getId: (card: Historical) => string): Mover => {

  const move$ = new Subject<void>()
  const move = () => { move$.next() }
  const id$ = card$.pipe(map(getId))

  const moveId$ = move$.pipe(
    withLatestFrom(id$),
    map(([, id]) => id))

  return {
    move,
    id$,
    moveId$,
  }
}
开发者ID:jamesbs,项目名称:flashcards,代码行数:18,代码来源:mover.ts

示例15: withLatestFrom1

 withLatestFrom1() {
   // emit every 5s
   const source = interval(5000);
   // emit every 1s
   const secondSource = interval(1000);
   const example = source.pipe(
     withLatestFrom(secondSource),
     map(([first, second]) => {
       return `First Source (5s): ${first} Second Source (1s): ${second}`;
     })
   );
   /*
     "First Source (5s): 0 Second Source (1s): 4"
     "First Source (5s): 1 Second Source (1s): 9"
     "First Source (5s): 2 Second Source (1s): 14"
     ...
   */
   const subscribe = example.subscribe(val => console.log(val));
 }
开发者ID:zwvista,项目名称:SampleMisc,代码行数:19,代码来源:combining.service.ts


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