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