Skip to content

Commit

Permalink
Merge pull request #120 from richardcrng/consistent-docs
Browse files Browse the repository at this point in the history
Consistent docs
  • Loading branch information
richardcrng authored Nov 8, 2019
2 parents ba3117b + e2162ee commit dc06a1b
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 81 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar_label: reduxLeaves

# `reduxLeaves(initialState, [reducersDict = {}])`

Returns a reducer function and an object.
Returns a reducer function and an actions object.

**See the [30 second demo](intro/demo.md)** for usage.

Expand Down
2 changes: 1 addition & 1 deletion docs/api/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sidebar_label: actions

## Arbitrary property paths

The `actions` object returned by `reduxLeaves` can take an arbitrary path of properties after it, which typically correspond to a 'leaf' at the corresponding path from your state.
The `actions` object returned by [`reduxLeaves`](../README.md) can take an arbitrary path of properties after it, which typically correspond to a 'leaf' at the corresponding path from your state.

```js
import reduxLeaves from 'redux-leaves'
Expand Down
8 changes: 4 additions & 4 deletions docs/defaults/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
id:
title: Default action creators by type
id: overview
title: Default action creators
hide_title: true
sidebar_label: By type
sidebar_label: Overview
---

# Default action creators by type
# Default action creators

All of the below action creators are availble through the [`create`](../api/create.md) API at any arbitrary leaf of [`actions`](../api/actions.md).

Expand Down
4 changes: 2 additions & 2 deletions docs/defaults/clear.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ sidebar_label: clear
---

# `clear(toNull = false)`
**create.clear**
**create(actionType).clear**
**`create.clear`**
**`create(actionType).clear`**
*Appropriate leaf state: any*

Returns an object that, *when dispatched to a store created with the original state tree*, clears the leaf's state.
Expand Down
2 changes: 1 addition & 1 deletion docs/defaults/drop.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar_label: drop

# `drop([n = 1])`
**`create.drop`**
**`create(actionType).drop**
**`create(actionType).drop`**
*Appropriate leaf state: array*

Returns an object that, *when dispatched to a store created with the original state tree*, drops the first `n` elements from the leaf's state.
Expand Down
2 changes: 1 addition & 1 deletion docs/defaults/path.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sidebar_label: path
Returns an object that, *when dispatched to a store created with the original state tree*, sets a property at `path` as `value`.

## Parameters
- `path` *(string[])*: the property path to set at
- `path` *(string[])*: an array of strings which represent the property path to set at
- `value` *(any)*: the value to set

## Returns
Expand Down
69 changes: 3 additions & 66 deletions docs/examples/basicExample.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,71 +54,8 @@ store.dispatch(actions.counterTwo.create.increment(10))
console.log(store.getState()) // { counterOne: 3, counterTwo: 10 }
```

## Default action creators
`increment` is one of many default action creators that Redux-Leaves writes for you.
Redux-Leaves has done all the hard work in providing you with a `reducer` and appropriate `actions` to `.create`!

If you want to add some custom action creators, look at the [intermediate example](intermediateExample.md).

Here are some other common defaults that you might like to use:

```js
import { createStore } from 'redux'
import reduxLeaves from 'redux-leaves'

const initialState = {
arr: [3, 'things', 'here'],
bool: false,
obj: {
nested: true
}
title: 'Redux-Leaves',
}

const [reducer, actions] = reduxLeaves(initialState)
const store = createStore(reducer)
```

### Arrays
```js
// push: push an element to an array
store.dispatch(actions.arr.create.push('new element'))
console.log(store.getState().arr) // [3, 'things', 'here', 'new element']

// drop: drop n elements from an array
store.dispatch(actions.arr.create.drop(2))
console.log(store.getState().arr) // [3, 'things']
```

### Booleans
```js
// toggle: toggles a boolean
store.dispatch(actions.bool.create.toggle())
console.log(store.getState().bool) // true

// off: make a boolean false (or 'on' for true)
store.dispatch(actions.bool.create.off())
console.log(store.getState().bool) // false
```

### Plain objects
```js
// assign: spreads properties
store.dispatch(actions.obj.create.assign({ deep: false }))
console.log(store.getState().obj) // { nested: true, deep: false }

// path: sets a value at a given path in the object
store.dispatch(actions.obj.create.path(['arbitrary', 'property'], 3))
console.log(store.getState().obj.arbitrary) // { property: 3 }
```

### Type agnostic
```js
// apply: updates state by applying a callback
store.dispatch(actions.title.create.apply(str => str.toUpperCase())
console.log(store.getState().title) // 'REDUX-LEAVES'

// update: changes state to the value provided
store.dispatch(actions.title.create.update('Redux-Leaves is GREAT'))
console.log(store.getState().title) // 'Redux-Leaves is GREAT'
```
`increment` is one of many [default action creators](../defaults/README.md) that Redux-Leaves writes for you, which cover most basic needs.

If you want to add some custom action creators, look at the [intermediate example](intermediateExample.md).
8 changes: 4 additions & 4 deletions website/pages/en/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,25 @@ class Index extends React.Component {
{[
{
title: 'Write once.',
content: 'Tired of writing repetitive reducer logic for different slices of state? With Redux-Leaves, you can <b>define reducer logic for an arbitrary leaf</b>.',
content: `Tired of writing repetitive reducer logic? With Redux-Leaves, you <a href=${docUrl('example/intermediate-example')}><b>define reducer logic once</b> and can <b>use it on an arbitrary leaf of state</b></a>.`,
image: `${baseUrl}img/code.png`,
imageAlign: 'top',
},
{
title: 'Reduce anywhere.',
content: 'Redux-Leaves makes that reducer logic instantly available to you for any leaf of your state shape, through <b>an intuitive action creator API</b>.',
content: `Redux-Leaves makes that reducer logic instantly available to you for any leaf of your state shape, through <a href=${docUrl('api/create')}><b>an intuitive action creator API</b></a>.`,
image: `${baseUrl}img/hierarchy.png`,
imageAlign: 'top',
},
{
title: 'No boilerplate.',
content: 'No more need to write action creators. Redux-Leaves <b>writes your action creators for you</b> based on the reducer logic that you supply.',
content: `No more need to write action creators. Redux-Leaves <a href=${docUrl('api/actions')}><b>writes your action creators for you</b></a> based on the reducer logic that you supply.`,
image: `${baseUrl}img/ban.svg`,
imageAlign: 'top',
},
{
title: 'Quick setup.',
content: `With multiple action creators built in by default, it takes <a href=${docUrl('example/simple-example')}>just 30 seconds</a> to get up and running.`,
content: `With multiple action creators built in by default, it takes <a href=${docUrl('example/basic-example')}>just 30 seconds</a> to get up and running.`,
image: `${baseUrl}img/fast.png`,
imageAlign: 'top',
},
Expand Down
2 changes: 1 addition & 1 deletion website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"api/create"
],
"Default creators": [
"defaults/by-type",
"defaults/overview",
{
"type": "subcategory",
"label": "any",
Expand Down

0 comments on commit dc06a1b

Please sign in to comment.