Skip to content

Commit

Permalink
Merge pull request #82 from richardcrng/sidebar
Browse files Browse the repository at this point in the history
Sidebar
  • Loading branch information
richardcrng authored May 18, 2019
2 parents 36da03d + 6036da1 commit 6675d6e
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 437 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
id: redux-leaves
title: Core API
hide_title: true
sidebar_label: reduxLeaves
sidebar_label: reduxLeaves API
---

# `reduxLeaves(initialState, [reducersDict = {}])`
Expand Down
8 changes: 4 additions & 4 deletions docs/create/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
id: creators
title: Action Creators
hide_title: true
sidebar_label: Action creators
sidebar_label: Actions
---

# Action Creators
# `actions`

With Redux-Leaves, all [leaf reducers](../leafReducers.md) that you define in your [`reducersDict`](../README.md#reducersdict) are automatically given a corresponding action creator.
## Action creators

The action creator has a [creator key](../creatorKeys.md) (`creatorKey`) corresponding to the one which the leaf reducer is defined with.
With Redux-Leaves, all [leaf reducers](../leafReducers.md) that you define in your [`reducersDict`](../README.md#reducersdict) are automatically given a corresponding action creator, keyed by the same [`creatorKey`](../creatorKeys.md).

`create[creatorKey]` is then an action creator function available at every single [leaf](../leaf/README.md) on our `actions` object.

Expand Down
4 changes: 2 additions & 2 deletions docs/create/asArray/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sidebar_label: Array

Every single leaf on our `actions` object has access to `create.asArray` methods.

If the leaf was initialised with array state, then these methods are also accessible directly through the [`create` API](../README.md).
If the leaf was initialised with array state, then these methods are also accessible directly through the [`create` API](../defaults.md).

If the current `leafState` is *not* an array, then it is first coerced into an array via lodash's [`_.toArray(leafState)`](https://lodash.com/docs/4.17.11#toArray) method, before the state is updated according to the action dispatched.

Expand All @@ -19,7 +19,7 @@ If the current `leafState` is *not* an array, then it is first coerced into an a
- [`.filter(callback)`](#filter(callback))
- [`.push(element, [index = -1], [replace = false])`](#createpushelement-index---1-replace--false)

[Back to all `create` action creators](../README.md#action-creators)
[Back to all `create` action creators](../defaults.md)

## `concat(array)`
**`create.asArray.concat`**
Expand Down
4 changes: 2 additions & 2 deletions docs/create/asBoolean/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sidebar_label: Boolean

Every single leaf on our `actions` object has access to `create.asBoolean` methods.

If the leaf was initialised with boolean state, then these methods are also accessible directly through the [`create` API](../README.md).
If the leaf was initialised with boolean state, then these methods are also accessible directly through the [`create` API](../defaults.md).

If the current `leafState` is *not* a boolean, then it is first coerced into a boolean as `!!leafState`, before the state is updated according to the action dispatched.

Expand All @@ -18,7 +18,7 @@ If the current `leafState` is *not* a boolean, then it is first coerced into a b
- [`.on()`](#on)
- [`.toggle()`](#toggle)

[Back to all `create` action creators](../README.md#action-creators)
[Back to all `create` action creators](../defaults.md)

## `off()`
**`create.asBoolean.off`**
Expand Down
4 changes: 2 additions & 2 deletions docs/create/asNumber/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ sidebar_label: Number

Every single leaf on our `actions` object has access to `create.asNumber` methods.

If the leaf was initialised with number state, then these methods are also accessible directly through the [`create` API](../README.md).
If the leaf was initialised with number state, then these methods are also accessible directly through the [`create` API](../defaults.md).

If the current `leafState` is *not* a number, then it is first coerced into an array via lodash's [`_.toNumber(leafState)`](https://lodash.com/docs/4.17.11#toNumber) method, before the state is updated according to the action dispatched.

## Action creators
- [`.increment([n = 1])`](#incrementn--1)

[Back to all `create` action creators](../README.md#action-creators)
[Back to all `create` action creators](../defaults.md)

## `increment([n = 1])`
**`create.asNumber.increment`**
Expand Down
4 changes: 2 additions & 2 deletions docs/create/asObject/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ sidebar_label: Object

Every single leaf on our `actions` object has access to `create.asObject` methods.

If the leaf was initialised with [plain object](https://lodash.com/docs/4.17.11#isPlainObject) state, then these methods are also accessible directly through the [`create` API](../README.md).
If the leaf was initialised with [plain object](https://lodash.com/docs/4.17.11#isPlainObject) state, then these methods are also accessible directly through the [`create` API](../defaults.md).

If the current `leafState` is *not* a plain object, then it is first coerced into a plain object via lodash's [`_.toPlainObject(leafState)`](https://lodash.com/docs/4.17.11#toPlainObject) method, before the state is updated according to the action dispatched.

## Action creators
- [`.assign(...sources)`](#assignsources)
- [`.set(path, value)`](#setpath-value)

[Back to all `create` action creators](../README.md#action-creators)
[Back to all `create` action creators](../defaults.md)

## `assign(...sources)`
**`create.asObject.assign`**
Expand Down
4 changes: 2 additions & 2 deletions docs/create/asString/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ sidebar_label: String

Every single leaf on our `actions` object has access to `create.asString` methods.

If the leaf was initialised with string state, then these methods are also accessible directly through the [`create` API](../README.md).
If the leaf was initialised with string state, then these methods are also accessible directly through the [`create` API](../defaults.md).

If the current `leafState` is *not* a string, then it is first coerced into a string via lodash's [`_.toString(leafState)`](https://lodash.com/docs/4.17.11#toString) method, before the state is updated according to the action dispatched.

## Action creators
- [`.concat(...strings)`](#concatstrings)
- [`.replace(pattern, replacement)`](#replacepattern-replacement)

[Back to all `create` action creators](../README.md#action-creators)
[Back to all `create` action creators](../defaults.md)

## `concat(...strings)`
**`create.asString.concat`**
Expand Down
15 changes: 9 additions & 6 deletions docs/create/defaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
id: defaults
title: Default Action Creators
hide_title: true
sidebar_label: Default action creators
sidebar_label: Universal
---

# `create`

Every single leaf on our `actions` object has a `create` property, through which we can access action creator functions.
Every single [leaf](../leaf/README.md) on our [`actions`](README.md) object has a `create` property, through which we can access action creator functions corresponding to the [`reducersDict`](../README.md#reducersdict) passed to to [`reduxLeaves`](../README.md).

In addition, `create` also contains a number of default action creators, which are listed below.

The default action creators can be overwritten by supplying your own [leaf reducer](../leafReducers.md) definition (with the same [`creatorKey`](../creatorKeys.md)) in your `reducersDict`.

## Action creators
### Universal
- [`.apply(callback)`](#applycallback)
- [`.clear([toNull = false])`](#cleartonull--false)
- [`.reset()`](#reset)
Expand All @@ -24,16 +29,14 @@ These are [spread into the `create` object](typeSpecific.md) depending on the `i
- [`create.asObject`](asObject/README.md#createasobject)
- [`create.asString`](asString/README.md#createasstring)

### Custom

It is also possible to add [custom action creators](../customReducers.md) by passing in a `customReducers` argument to [`reduxLeaves`](../README.md).


## `apply(callback)`
**`create.apply`**

Returns an object that, *when dispatched to a store created with the original state tree*, updates the leaf's state to the return value of `callback(leafState, entireState)`.

*Note: creating an action using `apply(callback)` violates Redux's recommendation that [actions should always be serializable](https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants), since the resultant action will have the function `callback` as its `payload`.*

### Parameters
- `callback` *(function)*: invoked by the leaf's reducer with two arguments, `leafState` and `entireState`

Expand Down
2 changes: 1 addition & 1 deletion docs/create/typeSpecific.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
id: type-specific
title: Type-Specific Action Creators
hide_title: true
sidebar_label: Type-specific creators
sidebar_label: Type-specific
---

# Type-specific `create` methods
Expand Down
221 changes: 0 additions & 221 deletions docs/customReducers.md

This file was deleted.

Loading

0 comments on commit 6675d6e

Please sign in to comment.