@heridux/core

0.0.4 • Public • Published

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

Examples

import Heridux from "@heridux/core"

const store = new Heridux("counterStore")

store.setInitialState({ counter : 0 })

Returns undefined

createAction

Create action/reducer couple

Parameters

  • name String action short name
  • reducer Function function to modify the state

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

  • name String action short name
  • options Object additional 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

  • store Object existing redux store
  • initialReducers Function reducing function

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

Package Sidebar

Install

npm i @heridux/core

Weekly Downloads

5

Version

0.0.4

License

MIT

Unpacked Size

33.2 kB

Total Files

6

Last publish

Collaborators

  • ybochatay