Okazari / k-simple-state

State manager for you components apps, the safe and easy way.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

k-simple-state

State manager for you components apps, the safe and easy way.

CircleCI Coverage Status NPM Version Size

Contents

Purpose

TODO

Why

TODO

Installation

  • yarn add k-simple-state
  • npm install --save k-simple-state

API

TODO

Examples

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' })

About

State manager for you components apps, the safe and easy way.

License:MIT License


Languages

Language:JavaScript 100.0%