| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 4× 5× 5× 1× 4× 2× 1× 2× | const createLocalState = (initialState) => {
const state = Object.assign({}, initialState)
return {
set: (key, value) => setValue(key, value, state),
get: function (key) {
if (arguments.length === 0) return state
return getValue(key, state)
}
}
}
const setValue = (key, value, state) => state[key] = value
const getValue = (key, state) => state[key]
export default createLocalState
|