State manager for you components apps, the safe and easy way.
TODO
TODO
yarn add k-simple-state
npm install --save k-simple-state
TODO
Full example
const { createState } = require('k-simple-state')
const saveToLocalStorage = store => next => (action) => {
// dispatch action
const res = next(action)
// save store to localStorage
window.localStorage.setItem('redux-store', JSON.stringify(store.getState()))
// return action for next middlewares
return res
}
const state = createState({
data: {
todos: { type: 'simpleObject' },
context: { type: 'keyValue', key: 'key' },
},
ui: {
bla: { type: 'simpleObject' },
testCustomReducer: (state, action) => {
if (!state) return 'oui'
if (action.type === 'testCustom') return action.payload
return state
},
},
config: state => state || {},
}, {
hideRedux: true,
middlewares: [saveToLocalStorage],
init: {
config: { this: 'is', from: { init: 'state' } },
},
})
state.ui.bla.set({ one: 'object', so: 'cool', right: true })
state.dispatch(state.ui.bla.set({ this: 'is', with: 'redux' }))
state.dispatch({ type: 'testCustom', payload: 'ok ça marche' })