@kofile/redux-lenses

0.0.4 • Public • Published

Redux Lenses

Build Status Commitizen friendly semantic-release

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 the lens
  • 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 expeting oldValue 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

Readme

Keywords

Package Sidebar

Install

npm i @kofile/redux-lenses

Weekly Downloads

4

Version

0.0.4

License

MIT

Last publish

Collaborators

  • bwgovos
  • juandagovos
  • matt_huntsberry
  • afine_govos
  • bthomas_govos
  • chrisburch-govos
  • rarzate
  • narekdaghlaryan
  • daniltarasov
  • kofilesystems
  • neezer
  • scottkof
  • jbalfantz
  • ngraves
  • arturhovhannisyan1994volo
  • rachel-ftw
  • warrenyoungkofile