Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Overwrite array values instead of merging them #89

Merged
merged 1 commit into from
Nov 20, 2017

Conversation

NLNicoo
Copy link
Contributor

@NLNicoo NLNicoo commented Nov 20, 2017

Before with this plugin, the default array values in the store would be overwritten by the saved localStorage array values (because it was using lodash.merge.) For example, the provided test in this PR passes in version 2.1.2.

The test fails on current master, because with deepmerge the default behavior is different as it really merges array values. So if I got a default state of: testArray: ['hello'] - and I use this plugin and reload the page 3 times, I got ['hello', 'hello', hello']

So it is better to really overwrite the array like before, this PR should do that.

edit: upon closer looking lodash.merge simply treats it as a object with numeric keys, so it would be overwritten as long as the saved array had more/equal items than the default array. Either way, completely overwriting seems to be the preferred way to me.

@robinvdvleuten
Copy link
Owner

wow thanks for figuring that one that @NLNicoo!

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

Successfully merging this pull request may close these issues.

2 participants