mirror of https://github.com/sgoudham/carbon.git
Load and store state from localStorage (#80)
* Load and store state from localStorage * remove idea of localStorage from get and set state fnsmain
parent
598ca88b98
commit
0c365218d6
@ -0,0 +1,13 @@
|
|||||||
|
import morph from 'morphmorph'
|
||||||
|
const KEY = 'CARBON_STATE'
|
||||||
|
|
||||||
|
const assign = morph.assign(KEY)
|
||||||
|
|
||||||
|
const parse = v => {
|
||||||
|
try {
|
||||||
|
return JSON.parse(v)
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getState = morph.compose(parse, morph.get(KEY))
|
||||||
|
export const saveState = (window, v) => assign(window, JSON.stringify(v))
|
Loading…
Reference in New Issue