lensify
v0.1.2
Published
Takes a (state) object and returns identical structure, where every key is a (ramda) lens
Downloads
24
Readme
Installation:
yarn add lensify
or if you prefer npm
:
npm install --save lensify
Development:
yarn install
npm run watch:js
run tests: npm test
How to use
import lensify from 'lensify';
const initialState = {
playerMoves: 0,
totalScore: 100,
deeper: {
deepProp: "foo",
},
};
const stateL = lensify(initialState);
Now stateL is an object with the exact same structure as initial state, except all keys are now (ramda) lenses.
You can use them in a redux reducer, for example:
const scoring = (state = initialState, action) => {
switch (action.type) {
case actionTypes.UPDATE_PLAYER_MOVES:
return R.over(stateL.playerMoves, R.add(action.moves), state);
case actionTypes.UPDATE_TOTAL_SCORE:
return R.over(stateL.totalScore, R.add(action.points), state);
default:
return state;
}
};
Contributing
Please see our guidelines in CONTRIBUTING.md
if you want to contribute something to this library.
License
MIT Licensed. Copyright (c) Kevin Decock 2017.