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


TypeScript store.createMiddleware函数代码示例

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


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

示例1: main

export function main() {
  return bootstrap(AsyncApp, [
      ELEMENT_PROBE_PROVIDERS,
      HTTP_PROVIDERS,
      provideStore({selectedReddit, postsByReddit}),
      usePreMiddleware(createMiddleware(redditPreMiddleware, [Reddit])),
      Reddit
  ])
  .catch(err => console.error(err));
}
开发者ID:andreyZavrazhnov,项目名称:ngrx-examples,代码行数:10,代码来源:bootstrap.ts

示例2: createMiddleware

import 'rxjs/add/operator/withLatestFrom';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/do';
import { Provider } from '@angular/core';
import { createMiddleware, Dispatcher } from '@ngrx/store';

import { SagaRunner } from './runner';

export const sagaMiddleware = createMiddleware(function middlewareFactory(
  dispatcher$: Dispatcher<any>, runner: SagaRunner) {

  return state$ => state$
    .withLatestFrom(dispatcher$, (state, action) => ({ state, action }))
    .do(runner)
    .map(({ state }) => state);
}, [ Dispatcher, SagaRunner ]);
开发者ID:CodeSequence,项目名称:store-saga,代码行数:16,代码来源:middleware.ts

示例3: createMiddleware

import 'rxjs/add/operator/do';
import {provide, Provider, Injector} from 'angular2/core';
import {createMiddleware} from '@ngrx/store';
import {RouterSubscriber} from './subscriber';
import {Router, Location} from 'angular2/router';

export default createMiddleware((router: Router, location: Location, rs: any) => {
  return state$ => state$.do(s => {
      if (s.router.url !== location.path()) {
        router.navigateByUrl(s.router.url);
      }
    })
}, [Router, Location, RouterSubscriber]);
开发者ID:MikeRyan52,项目名称:ngrx-store-router,代码行数:13,代码来源:middleware.ts

示例4: middlewareFactory

import 'rxjs/add/operator/withLatestFrom';
import 'rxjs/add/operator/map';
import { Injector, Provider } from 'angular2/core';
import { createMiddleware, Dispatcher } from '@ngrx/store';

import { SagaRunner } from './runner';

export function middlewareFactory(dispatcher$: Dispatcher<any>, injector: Injector) {
  let runner: SagaRunner;

  return state$ => state$
    .withLatestFrom(dispatcher$)
    .map(([ state, action ]) => {
      if( !runner ) {
        runner = injector.get(SagaRunner);
      }

      runner.next({ state, action });

      return state;
    });
}

export const sagaMiddleware = createMiddleware(middlewareFactory, [
  Dispatcher,
  Injector
]);
开发者ID:robwormald,项目名称:store-saga,代码行数:27,代码来源:middleware.ts

示例5: catch

        try {
            logger.groupEnd();
        } catch (e) {
            logger.log(`—— log end ——`);
        }
    });
    logBuffer.length = 0;
};

const preLogger = createMiddleware((log, options) => {
    return action$ => action$
        .do(action => {
            const {stateTransformer} = options;
            let logEntry = {
                started: timer.now(),
                startedTime: new Date(),
                prevState: stateTransformer(log.getValue()),
                action
            };
            log.next(logEntry);
        });
}, [ LOGGER, LOGGER_OPTIONS ]);

const postLogger = createMiddleware((log, loggerBuffer, options) => {
    const {stateTransformer} = options;
    return state$ => state$
        .do(state => {
            if(state.type !== INIT_ACTION) {
                let logInfo = log.getValue();
                //fixes issue caused by using with dev tools
                if(logInfo) {
开发者ID:fxck,项目名称:ngrx-store-logger,代码行数:31,代码来源:index.ts

示例6: createMiddleware

export const localStorageMiddleware = key => createMiddleware(localStorageService => {
  return state => {
    //sync specified state slice with local storage
    return state.do(state => localStorageService.setItem(key, state[key]));
  }
}, [LocalStorageService]);
开发者ID:Arahir,项目名称:ngrx-party,代码行数:6,代码来源:middleware.ts


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