Skip to content

Commit

Permalink
(fix): throw an error if no storage is configured
Browse files Browse the repository at this point in the history
- if the localStorage default is unsupported in the current
  environment (e.g. Node), then it should throw with a specific
  error instead of continuing and unexpectedly throwing on getItem
  - will still error out, so not a "fix" in that sense, but it now will
    throw a better, more understandable error
  • Loading branch information
agilgur5 committed Jul 27, 2019
1 parent 63053b9 commit a2f22a6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export const persist: IArgs = (name, store, options = {}) => {
) {
storage = AsyncLocalStorage
}
if (!storage) {
return Promise.reject('localStorage (the default storage engine) is not ' +
'supported in this environment. Please configure a different storage ' +
'engine via the `storage:` option.')
}

if (!jsonify) { jsonify = true } // default to true like mobx-persist
const whitelistDict = arrToDict(whitelist)
const blacklistDict = arrToDict(blacklist)
Expand Down

0 comments on commit a2f22a6

Please sign in to comment.