@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

/@kofile/redux-lenses/

    Package Sidebar

    Install

    npm i @kofile/redux-lenses

    Weekly Downloads

    2

    Version

    0.0.4

    License

    MIT

    Last publish

    Collaborators

    • vladimir.salvador
    • sergio.garcia
    • sergioatgovos
    • lilia.tirado
    • pantelissd
    • hd-kofile
    • oliverhoff
    • fernandofgovos
    • bwgovos
    • juandagovos
    • matt_huntsberry
    • chrisburch-govos
    • rarzate
    • narekdaghlaryan
    • kofilesystems
    • neezer
    • scottkof
    • jbalfantz
    • ngraves
    • arturhovhannisyan1994volo
    • rachel-ftw
    • warrenyoungkofile