vuejs-storage icon indicating copy to clipboard operation
vuejs-storage copied to clipboard

Fix merge when object is undefined

Open lucianodltec opened this issue 4 years ago • 4 comments

Please check changes in merge.ts. That allows restoring initial null object from storage.

lucianodltec avatar Feb 13 '21 13:02 lucianodltec

Codecov Report

Merging #40 (2b44bb7) into master (57721d9) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #40   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines           98        99    +1     
  Branches        13        14    +1     
=========================================
+ Hits            98        99    +1     
Impacted Files Coverage Δ
src/merge.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 57721d9...731db17. Read the comment docs.

codecov[bot] avatar Feb 13 '21 13:02 codecov[bot]

Could you add a test case about this change?

maple3142 avatar Feb 14 '21 01:02 maple3142

Hi mapple3142.

In my app, I have vuex namespaced two modules. On system module, it does have a state called "auth" which is an object like the below:

auth = { token: '.....hold jwt token...', access: { 'GET/system/user': true, 'GET/system/role: true }, user: { id: 'some-guid', name: 'xxxx', } }

So, configure vuejs-storage to persist "system.auth" state. It writes OK on localStorage, but when I try to reload app it's raising an exception that could not use operator "in" to retrieve "user". I guess the "merge" code I propposed creates an empty "user" object so it can interacts creating user attrs id and name.

Hope this helps to understand. If not I'll try to give you an sample app.

Thanks for your attention.

lucianodltec avatar Feb 14 '21 11:02 lucianodltec

I had similar problems with attributes containing null values

atilacamurca avatar Sep 16 '21 20:09 atilacamurca