@heridux/core
v0.0.4
Published
The easiest way to use and reuse redux stores or react internal states
Downloads
6
Maintainers
Readme
Table of Contents
Heridux
Creation of a Heridux store
Parameters
STATE_PROPERTY
String string name for this slice of state. Generated actions wille use this as a prefix.
Examples
import Heridux from "@heridux/core"
const store = new Heridux("counterStore")
setInitialState
Define the initial state of the store slice
Parameters
state
Object plain js state
Examples
import Heridux from "@heridux/core"
const store = new Heridux("counterStore")
store.setInitialState({ counter : 0 })
Returns undefined
createAction
Create action/reducer couple
Parameters
Examples
const myStore = new Heridux("myPartialStore")
myStore.setInitialState({
list : ["foo", "bar"]
})
myStore.createAction("pop", state => state.slice(0, -1))
Returns undefined
execAction
- **See: createAction **
Execute action registered by createAction method
Parameters
Examples
const myStore = new Heridux("myPartialStore")
myStore.setInitialState({
list : ["foo", "bar"]
})
myStore.createAction("pop", state => state.slice(0, -1))
myStore.register()
myStore.execAction("pop")
myStore.get("list") // ["foo"]
Returns undefined
getState
Get store slice
Parameters
_state
Object? global state (if not specified, call getState method of redux store)
Examples
import Heridux from "@heridux/core"
const store = new Heridux("counterStore")
store.setInitialState({ counter : 0 })
store.register()
store.getState() // { counter : 0 }
Returns Object store slice
get
Shortcut to get js value of a first level key
Parameters
key
String key name_state
Object? global state (if not specified, call getState method of redux store)
Examples
import Heridux from "@heridux/core"
const store = new Heridux("counterStore")
store.setInitialState({ counter : 0 })
store.register()
store.get("counter") === store.getState().counter // true
Returns any key value
register
Register heridux store in global redux store
Examples
import Heridux from "@heridux/core"
const store = new Heridux("counterStore")
store.setInitialState({ counter : 0 })
store.createAction("increment", state => {
state.counter++
})
store.register()
Returns undefined
createReduxStore
Create an empty redux store configured for Heridux. Add Redux DevTools if available
Examples
import Heridux from "@heridux/core"
export default Heridux.createReduxStore()
Returns Object redux store
connect
Connect Heridux to an existing redux store
Parameters
Examples
import { createStore } from "redux"
import Heridux from "@heridux/core"
const reducers = function(state){ return state }
const store = createStore(reducers)
Heridux.connect(store, reducers)
export default store
Returns undefined