Essential helper functions for managing immutable state. This is especially useful to write reducers for Redux or useReducer React Hook.
What's available:
clone
: creates a shallow clone of an objectdel
: deletes a property from a object at a given pathget
: gets a property value from a object at a given pathpick
: creates a new object with selected properties from an objectset
: sets a property value at a given path
A simple reducer that is compatible with Redux and useReducer React Hook.
import { del, set } from 'immutable-essentials';
export function values(state = {}, action) {
switch (action && action.type) {
case 'DEL VALUE': {
const { payload: { path } } = action;
return del(state, path);
}
case 'SET VALUE': {
const { payload: { merge, path, value } } = action;
return set(state, path, value, merge);
}
default:
return state;
}
}
export default values;
Bill Balmant |