modd
v0.0.4
Published
A simple immutablity utility, simplifies functional changes for react, redux, and other config modification.
Downloads
6
Readme
modd-js
A simple immutablity utility, simplifies functional changes for react, redux, and other config modification.
import {Modd, Apply, types} from 'modd';
let {Str, Arr, Map} = Modd.types;
// for type completion and Arr has _ as utility
let M = Modd({
user: {
uname: Str,
upw: Str,
},
pets: Arr({pname: Str})
});
// a caveat that you cannot use keys like "name" as key for functions.
let state = {
user: {
uname: 'my-old-name',
upw: 'new-pw'
},
pets: []
};
let newState = Apply(state)([
M.user.uname('new-name'), // {user: {uname: 'new-name', ...}, pets: ...}
M.user.uname(s => s.toUpperCase()) // {user: {uname: 'NEW-NAME', ...}, ...},
M.pets._(0).pname('fred') // {user: {...}, pets: [{pname: 'fred'}]}
]);