This repository was archived by the owner on Feb 4, 2022. It is now read-only.
Overwrite array values instead of merging them #89
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.