npm package: @heridux/core
Description: The easiest way to use and reuse redux stores or react internal states
Author: Yannick Bochatay
Latest version: 0.0.4

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [Heridux][1]
    -   [Parameters][2]
    -   [Examples][3]
    -   [setInitialState][4]
        -   [Parameters][5]
        -   [Examples][6]
    -   [createAction][7]
        -   [Parameters][8]
        -   [Examples][9]
    -   [execAction][10]
        -   [Parameters][11]
        -   [Examples][12]
    -   [getState][13]
        -   [Parameters][14]
        -   [Examples][15]
    -   [get][16]
        -   [Parameters][17]
        -   [Examples][18]
    -   [register][19]
        -   [Examples][20]
    -   [createReduxStore][21]
        -   [Examples][22]
    -   [connect][23]
        -   [Parameters][24]
        -   [Examples][25]

## Heridux

Creation of a Heridux store

### Parameters

-   `STATE_PROPERTY` **[String][26]** string name for this slice of state. Generated actions wille use this as a prefix.

### Examples

```javascript
import Heridux from "@heridux/core"

const store = new Heridux("counterStore")
```

### setInitialState

Define the initial state of the store slice

#### Parameters

-   `state` **[Object][27]** plain js state

#### Examples

```javascript
import Heridux from "@heridux/core"

const store = new Heridux("counterStore")

store.setInitialState({ counter : 0 })
```

Returns **[undefined][28]** 

### createAction

Create action/reducer couple

#### Parameters

-   `name` **[String][26]** action short name
-   `reducer` **[Function][29]** function to modify the state

#### Examples

```javascript
const myStore = new Heridux("myPartialStore")

myStore.setInitialState({
 list : ["foo", "bar"]
})

myStore.createAction("pop", state => state.slice(0, -1))
```

Returns **[undefined][28]** 

### execAction

-   **See: createAction
    **

Execute action registered by createAction method

#### Parameters

-   `name` **[String][26]** action short name
-   `options` **[Object][27]** additional parameters

#### Examples

```javascript
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][28]** 

### getState

Get store slice

#### Parameters

-   `_state` **[Object][27]?** global state (if not specified, call getState method of redux store)

#### Examples

```javascript
import Heridux from "@heridux/core"

const store = new Heridux("counterStore")

store.setInitialState({ counter : 0 })

store.register()

store.getState() // { counter : 0 }
```

Returns **[Object][27]** store slice

### get

Shortcut to get js value of a first level key

#### Parameters

-   `key` **[String][26]** key name
-   `_state` **[Object][27]?** global state (if not specified, call getState method of redux store)

#### Examples

```javascript
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

```javascript
import Heridux from "@heridux/core"

const store = new Heridux("counterStore")

store.setInitialState({ counter : 0 })

store.createAction("increment", state => {
  state.counter++
})

store.register()
```

Returns **[undefined][28]** 

### createReduxStore

Create an empty redux store configured for Heridux.
Add Redux DevTools if available

#### Examples

```javascript
import Heridux from "@heridux/core"

export default Heridux.createReduxStore()
```

Returns **[Object][27]** redux store

### connect

Connect Heridux to an existing redux store

#### Parameters

-   `store` **[Object][27]** existing redux store
-   `initialReducers` **[Function][29]** reducing function

#### Examples

```javascript
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][28]** 

[1]: #heridux

[2]: #parameters

[3]: #examples

[4]: #setinitialstate

[5]: #parameters-1

[6]: #examples-1

[7]: #createaction

[8]: #parameters-2

[9]: #examples-2

[10]: #execaction

[11]: #parameters-3

[12]: #examples-3

[13]: #getstate

[14]: #parameters-4

[15]: #examples-4

[16]: #get

[17]: #parameters-5

[18]: #examples-5

[19]: #register

[20]: #examples-6

[21]: #createreduxstore

[22]: #examples-7

[23]: #connect

[24]: #parameters-6

[25]: #examples-8

[26]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[27]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[28]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined

[29]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function