11import { createAction , handleActions } from 'redux-actions-helpers' ;
22
33// actions
4- export const startTransition = createAction ( '@@router/START_TRANSITION' , payload => ( { payload } ) ) ;
5- export const resolved = createAction ( '@@router/RESOLVED' , payload => ( { payload } ) ) ;
6- export const endTransition = createAction ( '@@router/END_TRANSITION' , payload => ( { payload } ) ) ;
4+ export const start = createAction ( '@@router/START' , payload => ( { payload } ) ) ;
5+ export const end = createAction ( '@@router/END' , payload => ( { payload } ) ) ;
76export const error = createAction ( '@@router/ERROR' , payload => ( { payload } ) ) ;
7+ export const cancel = createAction ( '@@router/CANCEL' ) ;
88
99// reducer
1010const initialState = {
@@ -18,19 +18,13 @@ const initialState = {
1818 isTransition : false
1919} ;
2020export const reducer = handleActions ( {
21- [ startTransition ] : ( state , { payload } ) => {
21+ [ start ] : ( state , { payload } ) => {
2222 return {
2323 ...state ,
2424 ...payload
2525 }
2626 } ,
27- [ resolved ] : ( state , { payload } ) => {
28- return {
29- ...state ,
30- ...payload
31- }
32- } ,
33- [ endTransition ] : ( state , { payload } ) => {
27+ [ end ] : ( state , { payload } ) => {
3428 return {
3529 ...state ,
3630 ...payload
@@ -41,21 +35,24 @@ export const reducer = handleActions({
4135 ...state ,
4236 ...payload
4337 }
38+ } ,
39+ [ cancel ] : ( ) => {
40+ return initialState ;
4441 }
4542} , { initialState } ) ;
4643
4744// hook
4845export const hookRedux = ( { dispatch } ) => ( {
4946 start : ( { path, location } ) => {
50- dispatch ( startTransition ( { path, location, isTransition : true } ) ) ;
47+ dispatch ( start ( { path, location, isTransition : true } ) ) ;
5148 } ,
52- resolve : ( { route, status, params, redirect } ) => {
53- dispatch ( resolved ( { route, status, params, redirect } ) ) ;
54- } ,
55- render : ( ) => {
56- dispatch ( endTransition ( { isTransition : false } ) ) ;
49+ render : ( { route, status, params, redirect } ) => {
50+ dispatch ( end ( { route, status, params, redirect, isTransition : false } ) ) ;
5751 } ,
5852 error : ( { error } ) => {
5953 dispatch ( error ( { error, isTransition : false } ) ) ;
54+ } ,
55+ cancel : ( ) => {
56+ dispatch ( cancel ( ) ) ;
6057 }
6158} ) ;
0 commit comments