all files / src/helpers/ local-state.js

100% Statements 11/11
100% Branches 2/2
100% Functions 1/1
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16                
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