Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Array default values #103

Closed
omsk359 opened this issue Feb 28, 2016 · 7 comments
Closed

Array default values #103

omsk359 opened this issue Feb 28, 2016 · 7 comments

Comments

@omsk359
Copy link

omsk359 commented Feb 28, 2016

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 pushed a commit that referenced this issue Feb 29, 2016
michaelcontento pushed a commit that referenced this issue Feb 29, 2016
@michaelcontento
Copy link
Owner

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 ...

@omsk359
Copy link
Author

omsk359 commented Mar 1, 2016

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
Copy link
Owner

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!

@omsk359
Copy link
Author

omsk359 commented Mar 1, 2016

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]}}

@michaelcontento
Copy link
Owner

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
Copy link
Author

omsk359 commented Mar 2, 2016

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

@michaelcontento
Copy link
Owner

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 :(

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants