@kofile/redux-lenses
v0.0.4
Published
A set of utility functions for dealing with redux state via Ramda lenses
Downloads
14
Maintainers
Readme
Redux Lenses
Usage
import { createStore } from 'redux'
import { set, createReducer } from '@kofile/redux-lenses'
const handlers = {
[ACTION_TYPE]: [
set(lens.to.desired.state).as(false),
set(lens.to.other.desired.state).with((payload, state) => newValue),
set(lens.to.other.desired.state).using(
(payload, state) => oldSliceValue => newValue
)
]
}
const reducer = createReducer(handlers)
export default createStore(reducer)
API
set
lens -> SetterObject
Takes in a lens to set a value at. Returns an object with 3 methods:
with
:setter -> ([lens, setter, 'set'])
setter
is a function that expects(action, state)
and returns a new value for thelens
as
:value -> ([lens, setter, 'set'])
value
is the value to set at that lens
using
:setter -> ([lens, setter, 'over'])
seter
0s a function that expects(action, state)
and returns a function expetingoldValue
of the lens and returns a new value for the lens.
createReducer
handlers -> (state, action) -> state
Takes in an object of { [actionTypes]: [...([lens, setter, methodName])] }
and returns a function of (state, action) -> nextState
.
Tests
$ yarn test
All tests are held inside of modules/index.test.js