Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit85479ba

Browse files
committed
(fix): handle non-existent key in storage
- if key is falsey, i.e. when storage has been cleared or has yet to be set to initial state, applySnapshot will fail and throw an error - so don't apply it if falsey, just skip the applySnapshot call - was thinking of applying `{}`, an empty object, if falsey, but this will reset the initial state of the store to its defaults - one might set initial state in `create({ ... })`, so that alternative doesn't work - getting the initial snapshot and setting it to itself was another alternative considered, but that would be quite complex with unnecessary operations, and might cause some unintended behavior due to whitelists, blacklists, etc applying - still need to think about the ramifications of those since applySnapshot doesn't merge, it just sets (and defaults are applied on top) - see also#1
1 parent91b8758 commit85479ba

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

‎persist.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const persist = (name, store, options = {}) => {
3030
returnstorage.getItem(name)
3131
.then((data)=>{
3232
constsnapshot=!jsonify ?data :JSON.parse(data)
33+
// don't apply falsey (which will error), leave store in initial state
34+
if(!snapshot){return}
3335
applySnapshot(store,snapshot)
3436
})
3537
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp