0.0.4 • Published 8 years ago
@kofile/redux-lenses v0.0.4
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'])setteris a function that expects(action, state)and returns a new value for thelens
as:value -> ([lens, setter, 'set'])valueis the value to set at that lens
using:setter -> ([lens, setter, 'over'])seter0s a function that expects(action, state)and returns a function expetingoldValueof 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 testAll tests are held inside of modules/index.test.js