Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Commit c65645b

Browse files
committed
Merge pull request #63 from nishp1/master
use FSA actions
2 parents 575d0e9 + 289ca86 commit c65645b

File tree

2 files changed

+62
-42
lines changed

2 files changed

+62
-42
lines changed

src/index.js

+18-14
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,24 @@ const SELECT_STATE = state => state.routing;
1010
function pushPath(path, state, { avoidRouterUpdate = false } = {}) {
1111
return {
1212
type: UPDATE_PATH,
13-
path: path,
14-
state: state,
15-
replace: false,
16-
avoidRouterUpdate: !!avoidRouterUpdate
13+
payload: {
14+
path: path,
15+
state: state,
16+
replace: false,
17+
avoidRouterUpdate: !!avoidRouterUpdate
18+
}
1719
};
1820
}
1921

2022
function replacePath(path, state, { avoidRouterUpdate = false } = {}) {
2123
return {
2224
type: UPDATE_PATH,
23-
path: path,
24-
state: state,
25-
replace: true,
26-
avoidRouterUpdate: !!avoidRouterUpdate
25+
payload: {
26+
path: path,
27+
state: state,
28+
replace: true,
29+
avoidRouterUpdate: !!avoidRouterUpdate
30+
}
2731
}
2832
}
2933

@@ -36,13 +40,13 @@ const initialState = {
3640
replace: false
3741
};
3842

39-
function update(state=initialState, action) {
40-
if(action.type === UPDATE_PATH) {
43+
function update(state=initialState, { type, payload }) {
44+
if(type === UPDATE_PATH) {
4145
return Object.assign({}, state, {
42-
path: action.path,
43-
changeId: state.changeId + (action.avoidRouterUpdate ? 0 : 1),
44-
state: action.state,
45-
replace: action.replace
46+
path: payload.path,
47+
changeId: state.changeId + (payload.avoidRouterUpdate ? 0 : 1),
48+
state: payload.state,
49+
replace: payload.replace
4650
});
4751
}
4852
return state;

test/index.js

+44-28
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@ describe('pushPath', () => {
1616
it('creates actions', () => {
1717
expect(pushPath('/foo', { bar: 'baz' })).toEqual({
1818
type: UPDATE_PATH,
19-
path: '/foo',
20-
replace: false,
21-
state: { bar: 'baz' },
22-
avoidRouterUpdate: false
19+
payload: {
20+
path: '/foo',
21+
replace: false,
22+
state: { bar: 'baz' },
23+
avoidRouterUpdate: false
24+
}
2325
});
2426

2527
expect(pushPath('/foo', undefined, { avoidRouterUpdate: true })).toEqual({
2628
type: UPDATE_PATH,
27-
path: '/foo',
28-
state: undefined,
29-
replace: false,
30-
avoidRouterUpdate: true
29+
payload: {
30+
path: '/foo',
31+
state: undefined,
32+
replace: false,
33+
avoidRouterUpdate: true
34+
}
3135
});
3236
});
3337
});
@@ -36,26 +40,32 @@ describe('replacePath', () => {
3640
it('creates actions', () => {
3741
expect(replacePath('/foo', { bar: 'baz' })).toEqual({
3842
type: UPDATE_PATH,
39-
path: '/foo',
40-
replace: true,
41-
state: { bar: 'baz' },
42-
avoidRouterUpdate: false
43+
payload: {
44+
path: '/foo',
45+
replace: true,
46+
state: { bar: 'baz' },
47+
avoidRouterUpdate: false
48+
}
4349
});
4450

4551
expect(replacePath('/foo', undefined, { avoidRouterUpdate: true })).toEqual({
4652
type: UPDATE_PATH,
47-
path: '/foo',
48-
state: undefined,
49-
replace: true,
50-
avoidRouterUpdate: true
53+
payload: {
54+
path: '/foo',
55+
state: undefined,
56+
replace: true,
57+
avoidRouterUpdate: true
58+
}
5159
});
5260

5361
expect(replacePath('/foo', undefined, { avoidRouterUpdate: false })).toEqual({
5462
type: UPDATE_PATH,
55-
path: '/foo',
56-
state: undefined,
57-
replace: true,
58-
avoidRouterUpdate: false
63+
payload: {
64+
path: '/foo',
65+
state: undefined,
66+
replace: true,
67+
avoidRouterUpdate: false
68+
}
5969
});
6070
});
6171
});
@@ -69,8 +79,10 @@ describe('routeReducer', () => {
6979
it('updates the path', () => {
7080
expect(routeReducer(state, {
7181
type: UPDATE_PATH,
72-
path: '/bar',
73-
replace: false
82+
payload: {
83+
path: '/bar',
84+
replace: false
85+
}
7486
})).toEqual({
7587
path: '/bar',
7688
replace: false,
@@ -82,9 +94,11 @@ describe('routeReducer', () => {
8294
it('respects replace', () => {
8395
expect(routeReducer(state, {
8496
type: UPDATE_PATH,
85-
path: '/bar',
86-
replace: true,
87-
avoidRouterUpdate: false
97+
payload: {
98+
path: '/bar',
99+
replace: true,
100+
avoidRouterUpdate: false
101+
}
88102
})).toEqual({
89103
path: '/bar',
90104
replace: true,
@@ -96,9 +110,11 @@ describe('routeReducer', () => {
96110
it('respects `avoidRouterUpdate` flag', () => {
97111
expect(routeReducer(state, {
98112
type: UPDATE_PATH,
99-
path: '/bar',
100-
replace: false,
101-
avoidRouterUpdate: true
113+
payload: {
114+
path: '/bar',
115+
replace: false,
116+
avoidRouterUpdate: true
117+
}
102118
})).toEqual({
103119
path: '/bar',
104120
replace: false,

0 commit comments

Comments
 (0)