Skip to content

spautz/tiny-immutable-set

main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

tiny-immutable-set

A minimal, immutable, deep set utility for Javascript objects and arrays.

Inspired by, and based on, NickGard's tiny-get

npm version build status dependencies status gzip size test coverage

Usage

import { set } from 'tiny-immutable-set';

const newState = set(state, 'deep.path', newValue);

The original state is not modified.

Notes

  • If you're using lodash then you don't need this: see this thread for alternatives.
  • Unlike most other setter utilities, this is slightly faster if you use a string for the path, instead of an array: set(obj, "deep.path[123]", newVal) instead of set(obj, ["deep", "path", 123], newVal).
  • The small bundle size of this library comes with a slight speed tradeoff. This library is a little slower than immutable-assign and immutable.js, but a little faster than Immer and seamless-immutable. See full benchmark here.

About

Minimal, immutable deep set

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published