immutable-essentials
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

npm node license

immutable-essentials

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 object
  • del: deletes a property from a object at a given path
  • get: gets a property value from a object at a given path
  • pick: creates a new object with selected properties from an object
  • set: sets a property value at a given path

Example

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;

Maintainer

billbalm-avatar
Bill Balmant

Readme

Keywords

Package Sidebar

Install

npm i immutable-essentials

Weekly Downloads

0

Version

1.1.2

License

MIT

Unpacked Size

9.77 kB

Total Files

28

Last publish

Collaborators

  • billbalm