Skip to content

Commit

Permalink
feat(*): export redux middleware for transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
elboman committed Sep 25, 2017
1 parent 3d7c39d commit 8170b71
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 22 deletions.
16 changes: 3 additions & 13 deletions core/applyHooks.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
/**
* @module core
*/ /** */
import {
UIRouter,
Transition,
HookResult,
TransitionHookFn,
} from '@uirouter/core';
import { HookResult, Transition, TransitionHookFn, UIRouter } from '@uirouter/core';
import { Rejection, RejectType } from '@uirouter/core';
import { Store, Action } from 'redux';
import { Store } from 'redux';

import {
START_TRANSITION,
IGNORED_TRANSITION,
REDIRECTED_TRANSITION,
FINISH_TRANSITION,
} from './actions';
import { FINISH_TRANSITION, IGNORED_TRANSITION, REDIRECTED_TRANSITION, START_TRANSITION } from './actions';

/** @hidden */
const hookResult: HookResult = true;
Expand Down
2 changes: 2 additions & 0 deletions core/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { createReduxPlugin } from './reduxPlugin';
export { routerReducer } from './reducer';
export { default as createRouterMiddleware } from './middleware';
export { triggerTransition } from './actions';
6 changes: 4 additions & 2 deletions core/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { UIRouter } from '@uirouter/core';

import { TRIGGER_TRANSITION } from './actions';

export default function routerMiddleware(router) {
export default function createRouterMiddleware(router: UIRouter) {
return () => next => action => {
if (action.type !== TRIGGER_TRANSITION) {
return next(action);
}

const { to, params } = action;
// TODO: trigger transition
router.stateService.go(to, params);
};
}
7 changes: 1 addition & 6 deletions core/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
START_TRANSITION,
IGNORED_TRANSITION,
REDIRECTED_TRANSITION,
FINISH_TRANSITION,
} from './actions';
import { FINISH_TRANSITION, IGNORED_TRANSITION, START_TRANSITION } from './actions';

const initialState = {
transitioning: false,
Expand Down
2 changes: 1 addition & 1 deletion core/reduxPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { UIRouter } from '@uirouter/core';
import { Store } from 'redux';
import { ReduxPlugin } from './interface';

import { applyHooks } from './applyHooks';
import { ReduxPlugin } from './interface';

export function reduxPluginFactory(name: string, store: Store<any>) {
return function(router: UIRouter): ReduxPlugin {
Expand Down

0 comments on commit 8170b71

Please sign in to comment.