Add store utils

release
Etienne Lemay 2016-07-06 13:34:04 -04:00
parent 122afc07ce
commit 8a022b69fa
2 changed files with 26 additions and 0 deletions

1
src/utils/index.js Normal file
View File

@ -0,0 +1 @@
export {default as store} from './store'

25
src/utils/store.js Normal file
View File

@ -0,0 +1,25 @@
const NAMESPACE = 'emoji-picker'
function update(state) {
for (let key in state) {
let value = state[key]
set(key, value)
}
}
function set(key, value) {
if (!('localStorage' in window)) return
window.localStorage[`${NAMESPACE}.${key}`] = JSON.stringify(value)
}
function get(key) {
if (!('localStorage' in window)) return
var value = window.localStorage[`${NAMESPACE}.${key}`]
if (value) {
return JSON.parse(value)
}
}
export default { update, set, get }