Skip to content

Commit 9e9b70b

Browse files
authored
Merge pull request #56 from mamcgrath/fix_handle_multiple_nested_paths
Fix handling of nested paths
2 parents 832ca27 + 75e269d commit 9e9b70b

File tree

6 files changed

+23
-7
lines changed

6 files changed

+23
-7
lines changed

lib/getStateFromCookies.js

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/getStateFromCookies.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-cookies-middleware",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "redux-cookies-middleware is a redux middleware which watches for changes in redux state & store them to browser cookie.",
55
"keywords": [
66
"redux",
@@ -57,6 +57,7 @@
5757
"webpack": "^3.3.0"
5858
},
5959
"dependencies": {
60-
"js-cookie": "^2.1.4"
60+
"js-cookie": "^2.1.4",
61+
"lodash": "^4.17.15"
6162
}
6263
}

src/getStateFromCookies.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import merge from 'lodash/merge';
12
import { getCookie as getBrowserCookie } from './cookieApi';
23

34
/**
@@ -45,7 +46,7 @@ const getStateFromCookies = (
4546
return getStateFromPath(path, valueFromCookie);
4647
});
4748
return pathStates
48-
.reduce((finalState, pathState) => ({ ...finalState, ...pathState }), preloadedState);
49+
.reduce((finalState, pathState) => (merge({}, finalState, pathState)), preloadedState);
4950
};
5051

5152
export default getStateFromCookies;

test/getStoreFromCookies.spec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getStateFromCookies } from '../src';
55
describe('getStateFromCookies', () => {
66
const userId = 1;
77
const authToken = 'xxxxx';
8+
const key = 'xxx';
89
const geolocation = {
910
lat: 12.34,
1011
lon: 56.78
@@ -23,7 +24,8 @@ describe('getStateFromCookies', () => {
2324
initialState = {
2425
userId: null,
2526
auth: {
26-
authToken: null
27+
authToken: null,
28+
key: null
2729
},
2830
geolocation: {},
2931
ui: {
@@ -33,6 +35,7 @@ describe('getStateFromCookies', () => {
3335

3436
jsCookie.set('userId', JSON.stringify(userId));
3537
jsCookie.set('authToken', JSON.stringify(authToken));
38+
jsCookie.set('key', JSON.stringify(key));
3639
jsCookie.set('geolocation', JSON.stringify(geolocation));
3740
jsCookie.set('checkout', JSON.stringify(checkout));
3841
});
@@ -42,6 +45,7 @@ describe('getStateFromCookies', () => {
4245
userId: { name: 'userId' },
4346
geolocation: { name: 'geolocation' },
4447
'auth.authToken': { name: 'authToken' },
48+
'auth.key': { name: 'key' },
4549
'ui.checkout': { name: 'checkout' }
4650
};
4751

@@ -50,6 +54,7 @@ describe('getStateFromCookies', () => {
5054
// expectations
5155
expect(value.userId).toEqual(userId);
5256
expect(value.auth.authToken).toEqual(authToken);
57+
expect(value.auth.key).toEqual(key);
5358
expect(value.geolocation).toEqual(geolocation);
5459
expect(value.ui.checkout).toEqual(checkout);
5560
});

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,6 +2908,11 @@ lodash@^4.0.1, lodash@^4.14.0, lodash@^4.16.6, lodash@^4.17.4, lodash@^4.2.0, lo
29082908
version "4.17.4"
29092909
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
29102910

2911+
lodash@^4.17.15:
2912+
version "4.17.15"
2913+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
2914+
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
2915+
29112916
29122917
version "1.2.5"
29132918
resolved "https://registry.yarnpkg.com/log-driver/-/log-driver-1.2.5.tgz#7ae4ec257302fd790d557cb10c97100d857b0056"

0 commit comments

Comments
 (0)