0.0.4 • Published 7 years ago

@kofile/redux-lenses v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
7 years ago

Redux Lenses

npm.io

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

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.1.0

7 years ago

0.0.0

7 years ago