choo-persist
Advanced tools
Comparing version 3.0.0 to 3.0.1
13
index.js
@@ -24,3 +24,7 @@ var mutate = require('xtend/mutable') | ||
bus.removeListener('*', listener) | ||
window.localStorage.removeItem(name) | ||
try { | ||
window.localStorage.removeItem(name) | ||
} catch (e) { | ||
bus.emit('log:warn', 'Coun not wipe localStorage ' + name) | ||
} | ||
bus.emit('log:warn', 'Wiping localStorage ' + name) | ||
@@ -31,5 +35,10 @@ }) | ||
var savedState = filter ? filter(state) : state | ||
window.localStorage.setItem(name, JSON.stringify(savedState)) | ||
try { | ||
window.localStorage.setItem(name, JSON.stringify(savedState)) | ||
} catch (e) { | ||
bus.removeListener('*', listener) | ||
bus.emit('log:warn', 'Cound not set item to localStorage ' + name) | ||
} | ||
} | ||
} | ||
} |
{ | ||
"name": "choo-persist", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Synchronize choo state with indexedDB", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,4 @@ # choo-persist [![stability][0]][1] | ||
Synchronize [choo][choo] state with `localStorage` | ||
Persist [choo][choo] state to [localStorage][mdn]. localStorage is supported | ||
by [all major browsers][caniuse]. | ||
@@ -20,8 +21,7 @@ ## Usage | ||
### `instance = persist([opts])` | ||
Create a new `indexedDB` database instance, and call the callback with the | ||
plugin when done. Can take an optional first argument of options: | ||
- __opts.name:__ default `'app'`; provide a name for the indexedDB database | ||
- __opts.filter(state):__ modify the state that's about to be written to the | ||
IndexedDB database. Useful to strip values that cannot be serialized to | ||
IndexedDB. | ||
Load the app state from `localStorage` and set up listeners to write the state | ||
back on every event. Can take an optional argument of options: | ||
- __opts.name:__ default `'choo-persist'`; the `localStorage` key. | ||
- __opts.filter(state):__ modify the state that's about to be saved. Useful | ||
for removing values that cannot be serialized to JSON. | ||
@@ -70,4 +70,4 @@ ```js | ||
[11]: https://github.com/feross/standard | ||
[caniuse]: http://caniuse.com/#feat=indexeddb | ||
[mdn]: https://developer.mozilla.org/en/docs/Web/API/IndexedDB_API | ||
[caniuse]: http://caniuse.com/#feat=namevalue-storage | ||
[mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage | ||
[choo]: https://github.com/yoshuawuyts/choo |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5722
35