https://github.com/rvikmanis/redux-fp
Functional programming helpers for Redux.
https://github.com/rvikmanis/redux-fp
functional-programming helpers point-free reducer redux utility-library
Last synced: 6 months ago
JSON representation
Functional programming helpers for Redux.
- Host: GitHub
- URL: https://github.com/rvikmanis/redux-fp
- Owner: rvikmanis
- License: mit
- Created: 2016-08-20T08:36:35.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-11-05T13:39:26.000Z (almost 8 years ago)
- Last Synced: 2025-04-09T07:39:01.713Z (6 months ago)
- Topics: functional-programming, helpers, point-free, reducer, redux, utility-library
- Language: JavaScript
- Homepage:
- Size: 85.9 KB
- Stars: 28
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-fp
Functional programming helpers for Redux.
[](https://travis-ci.org/rvikmanis/redux-fp)
[](https://codecov.io/gh/rvikmanis/redux-fp)**Table of contents**
- [Updaters vs. reducers](#updaters-vs-reducers)
- [Purpose](#purpose)
- [Installation](#installation)
- [API reference](#api-reference)## Updaters vs. reducers
*Updater* is a type of function that takes an action and
returns another function that takes the state and produces a result.```javascript
action => state => {
// Do something
}
```Yes, they are just curried reducers with reversed argument order.
### Using with utility libraries
Unlike reducers, updaters compose nicely with existing tools like lodash/fp or Ramda.
Let's create an updater that replaces a part
of the state with the action's payload. We will use lodash/fp's `set` helper to illustrate the point.```javascript
import { set } from 'lodash/fp'
const changeFoo = action => set('foo', action.payload)
```Note that I've eliminated state from the definition of our updater, and called `set` with two, not three, arguments.
This works because when `set` is called without
the third argument, it returns a function that takes the missing argument and produces a result.
That function becomes the inner function of our updater and receives the state.The paradigm is called [point-free style](https://en.wikipedia.org/wiki/Tacit_programming), and
if you're not familiar with it, check out
[Lucas Reis' introductory article](http://lucasmreis.github.io/blog/pointfree-javascript/).### Compatibility
To create a Redux store, just wrap the root updater in a reducer:
```javascript
createStore((s, a) => updater(a)(s))
```## Purpose
*redux-fp* provides a set of useful utilities and enhancers like `combine`, `withDefaultState` or `mapState`
that help working with updaters.Check out the [API reference](#api-reference) for a full list of helpers, complete with descriptions and usage examples.
## Installation
**Node**
`npm i --save redux-fp`
Or as a development dependency:
`npm i --save-dev redux-fp`
**Browser**
```html
```
Makes the library available globally as `ReduxFp`.
## API reference
See [docs/API.md](docs/API.md)