Array default values #103

Closed
opened 2016-02-28 03:32:48 +00:00 by omsk359 · 7 comments
omsk359 commented 2016-02-28 03:32:48 +00:00 (Migrated from github.com)

Hi! I have a test reducer:
myReducer = (state = { arr: [1, 2, 3] }, action) => action.type == 'TEST' ? { arr: [5] } : state
It's save to store correctly after dispatch: { arr: 5 }
But after load it's has a value { arr: [5, 2, 3] }.
Lo-dash _.merge problem.

Hi! I have a test reducer: `myReducer = (state = { arr: [1, 2, 3] }, action) => action.type == 'TEST' ? { arr: [5] } : state` It's save to store correctly after dispatch: `{ arr: 5 }` But after load it's has a value `{ arr: [5, 2, 3] }`. Lo-dash `_.merge` problem.
michaelcontento commented 2016-02-29 09:37:43 +00:00 (Migrated from github.com)

Hi! Could you provide me some example code?

I've tried to reproduce this problem but with no success. For me everything looks and behaves as is should ...

Hi! Could you provide me some example code? I've tried to [reproduce this problem](https://github.com/michaelcontento/redux-storage/commit/76f464701de6c760a52c3285dedad3e59183e7f2) but with no success. For me everything looks and behaves as is should ...
omsk359 commented 2016-03-01 00:14:49 +00:00 (Migrated from github.com)

Maybe I use it wrong, but

  1. Load page, reducer init: arr = [1, 2, 3]
  2. redux-storage load nothing: arr = [1, 2, 3]
  3. dispatch: arr = [5]
  4. Reload page, reducer init: arr = [1, 2, 3]
  5. redux-storage load: arr = [5, 2, 3]
Maybe I use it wrong, but 1. Load page, reducer init: `arr = [1, 2, 3]` 2. redux-storage load nothing: `arr = [1, 2, 3]` 3. dispatch: `arr = [5]` 4. Reload page, reducer init: `arr = [1, 2, 3]` 5. redux-storage load: `arr = [5, 2, 3]`
michaelcontento commented 2016-03-01 06:57:07 +00:00 (Migrated from github.com)

Hm .. strange. Would it be possible for you to inspect the state of the engine right BEFORE you trigger the load action? This depends on the engine in use but for redux-storage-engine-localstorage the output of:

console.log(store.getState());
console.log(localStorage.getItem(key));

would be very interesting!

Hm .. strange. Would it be possible for you to inspect the state of the engine right BEFORE you trigger the load action? This depends on the engine in use but for [redux-storage-engine-localstorage](https://github.com/michaelcontento/redux-storage-engine-localstorage) the output of: ``` js console.log(store.getState()); console.log(localStorage.getItem(key)); ``` would be very interesting!
omsk359 commented 2016-03-01 11:14:10 +00:00 (Migrated from github.com)

Ok. It's my store.js now.
0. I open page and run clearStorage()

  1. Reload page. My out:

before1: [1, 2, 3]
before2: null
[13:54:46] [Dispatching] {"type":"REDUX_STORAGE_LOAD","payload":{}}
[13:54:46] [Store] {"myReducer":{"arr":[1,2,3]}}
Loaded state: undefined
after1: [1, 2, 3]
after2: null

  1. I execute store.dispatch({type: 'TEST'})
  2. Reload page again:

before1: [1, 2, 3]
before2: {"myReducer":{"arr":[5]}}
[13:55:39] [Dispatching] {"type":"REDUX_STORAGE_LOAD","payload":{"myReducer":{"arr":[5]}}}
[13:55:39] [Store] {"myReducer":{"arr":[5,2,3]}}
Loaded state: [5]
after1: [5, 2, 3]
after2: {"myReducer":{"arr":[5]}}

Ok. It's my [store.js](https://github.com/omsk359/issues/blob/master/redux-storage/store.js) now. 0. I open page and run `clearStorage()` 1. Reload page. My out: > before1: [1, 2, 3] > before2: null > [13:54:46] [Dispatching] {"type":"REDUX_STORAGE_LOAD","payload":{}} > [13:54:46] [Store] {"myReducer":{"arr":[1,2,3]}} > Loaded state: undefined > after1: [1, 2, 3] > after2: null 1. I execute `store.dispatch({type: 'TEST'})` 2. Reload page again: > before1: [1, 2, 3] > before2: {"myReducer":{"arr":[5]}} > [13:55:39] [Dispatching] {"type":"REDUX_STORAGE_LOAD","payload":{"myReducer":{"arr":[5]}}} > [13:55:39] [Store] {"myReducer":{"arr":[5,2,3]}} > Loaded state: [5] > after1: [5, 2, 3] > after2: {"myReducer":{"arr":[5]}}
michaelcontento commented 2016-03-01 16:00:48 +00:00 (Migrated from github.com)

Could you also please paste the result of npm list so that I can see the used versions of all involved libraries? I still have no clue whats the root cause of this :(

And a last question: in which browsers have you tested this?

Could you also please paste the result of `npm list` so that I can see the used versions of all involved libraries? I still have no clue whats the root cause of this :( And a last question: in which browsers have you tested this?
omsk359 commented 2016-03-02 07:41:31 +00:00 (Migrated from github.com)

I use Meteor 1.2.1, it's meteor list out and packages.json file used by meteorhacks:npm.
Browser: Chrome 48.

I don't spend a lot of time, but quickly looked at your code. Are you use lodash merge function after action Load? If so, it may be the cause because
_.isEqual(_.merge([1,2,3], [5]), [5,2,3]) // true

I use Meteor 1.2.1, it's [`meteor list`](https://github.com/omsk359/issues/blob/master/redux-storage/meteor_list.txt) out and [packages.json](https://github.com/omsk359/issues/blob/master/redux-storage/packages.json) file used by meteorhacks:npm. Browser: Chrome 48. I don't spend a lot of time, but quickly looked at your code. Are you use lodash `merge` function after action Load? If so, it may be the cause because `_.isEqual(_.merge([1,2,3], [5]), [5,2,3]) // true`
michaelcontento commented 2016-04-28 07:59:12 +00:00 (Migrated from github.com)

redux-storage-merger-simple is the default merger used by redux-storage. Please have a look at it and create a issue there with some code to reproduce this issue.

I'm closing this issue here now, as a) it's no longer related to the code in this repository and b) I'm still unable to reproduce this :(

[redux-storage-merger-simple](https://github.com/michaelcontento/redux-storage-merger-simple) is the default merger used by redux-storage. Please have a look at it and create a issue there with some code to reproduce this issue. I'm closing this issue here now, as a) it's no longer related to the code in this repository and b) I'm still unable to reproduce this :(
This discussion has been locked. Commenting is limited to contributors.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MichaelContento/redux-storage#103
No description provided.