Skip to content

Commit

Permalink
📝 README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien JUIF committed Jul 19, 2017
1 parent 208ff6f commit 2c9ebe8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export default map({ key: 'id', path: 'api', name: 'todos' })
```
That's it, you just exported the reducer function and now you can register it through combinerReducer in Redux.

In this example, we have a `todos` reducer, it has to be combined into `state.api.todos`
In this example, we have a `todos` reducer, it has to be combined into `state.api.todos`.

One more thing, this lib handle state immutability for you !

## Why
We like to write Redux code as simple as possible and use its middlewares to handle real world problems.
Expand Down Expand Up @@ -202,7 +204,7 @@ todos.get('1')(state)
| signature | description | comment |
|---|---|---|
|`mapAction(<mapper(action)>)`| create middleware and map only redux action | mapper(action) is mandatory |
|`mapPayload(<mapper(payload)>)`| create middleware and map only redux payload | mapper(payload) is mandatory |
|`mapPayload(<regex>)(<mapper(payload)>)`| create middleware and map the payload of the corresponding redux actions type by the regex |

#### Example, we create a middleware but we modify only the action :
```es6
Expand All @@ -213,7 +215,7 @@ import { mapAction } from 'trampss-redux-factory/helpers'
// define a function to map action
const mapper = action => ({ ...action, type: `SET_${action.type}` })
// create your reducer and transform the type of action before core middleware
export default factory({ pre: [mapAction(mapper)] })('id')('api.raw')('todos')
export default factory({ pre: [mapAction(mapper)] })({ key: 'id', path: 'api.raw', name: 'todos' })
```

#### Example, we create a middleware but we modify only the payload :
Expand All @@ -225,5 +227,5 @@ import { mapPayload } from 'trampss-redux-factory/helpers'
// define a function to map payload
const mapper = payload => payload.map(p => ({ ...p, id: `ID_${p.id}` }))
// create your reducer and transform the payload before core middleware
export default factory({ pre: [mapPayload(/SET_TODOS/)(mapper)] })('id')('api.raw')('todos')
export default factory({ pre: [mapPayload(/SET_TODOS/)(mapper)] })({ key: 'id', path: 'api.raw', name: 'todos' })
```

0 comments on commit 2c9ebe8

Please sign in to comment.