Skip to content

Commit 8170b71

Browse files
committed
feat(*): export redux middleware for transitions
1 parent 3d7c39d commit 8170b71

File tree

5 files changed

+11
-22
lines changed

5 files changed

+11
-22
lines changed

core/applyHooks.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
/**
22
* @module core
33
*/ /** */
4-
import {
5-
UIRouter,
6-
Transition,
7-
HookResult,
8-
TransitionHookFn,
9-
} from '@uirouter/core';
4+
import { HookResult, Transition, TransitionHookFn, UIRouter } from '@uirouter/core';
105
import { Rejection, RejectType } from '@uirouter/core';
11-
import { Store, Action } from 'redux';
6+
import { Store } from 'redux';
127

13-
import {
14-
START_TRANSITION,
15-
IGNORED_TRANSITION,
16-
REDIRECTED_TRANSITION,
17-
FINISH_TRANSITION,
18-
} from './actions';
8+
import { FINISH_TRANSITION, IGNORED_TRANSITION, REDIRECTED_TRANSITION, START_TRANSITION } from './actions';
199

2010
/** @hidden */
2111
const hookResult: HookResult = true;

core/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export { createReduxPlugin } from './reduxPlugin';
22
export { routerReducer } from './reducer';
3+
export { default as createRouterMiddleware } from './middleware';
4+
export { triggerTransition } from './actions';

core/middleware.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import { UIRouter } from '@uirouter/core';
2+
13
import { TRIGGER_TRANSITION } from './actions';
24

3-
export default function routerMiddleware(router) {
5+
export default function createRouterMiddleware(router: UIRouter) {
46
return () => next => action => {
57
if (action.type !== TRIGGER_TRANSITION) {
68
return next(action);
79
}
810

911
const { to, params } = action;
10-
// TODO: trigger transition
12+
router.stateService.go(to, params);
1113
};
1214
}

core/reducer.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
START_TRANSITION,
3-
IGNORED_TRANSITION,
4-
REDIRECTED_TRANSITION,
5-
FINISH_TRANSITION,
6-
} from './actions';
1+
import { FINISH_TRANSITION, IGNORED_TRANSITION, START_TRANSITION } from './actions';
72

83
const initialState = {
94
transitioning: false,

core/reduxPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { UIRouter } from '@uirouter/core';
22
import { Store } from 'redux';
3-
import { ReduxPlugin } from './interface';
43

54
import { applyHooks } from './applyHooks';
5+
import { ReduxPlugin } from './interface';
66

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

0 commit comments

Comments
 (0)