1.0.0 • Published 7 years ago

mutability-helper v1.0.0

Weekly downloads
7
License
MIT
Repository
github
Last release
7 years ago

mutability-helper

NPM version Build status Test coverage Downloads

Mutate a piece of data in place leveraging a convenient set of commands. Based on immutability-helper.

import update from 'mutability-helper';

const state1 = ['x'];
update(state1, {$push: ['y']});
// state1 === ['x', 'y']

Overview

Originally, the immutability-helper's selling point was the fact that it didn't mutated the piece of data at all, returning a mutated copy of it to be used instead.

But, sometimes you may want to update a piece of data in place, leveraging those nice and convenient commands from that come from immutability-helper (and they were originally inspired by MongoDB's query language).

That is why this project exists and it uses the same commands API from the original immutability-helper.

update()

update() provides simple syntactic sugar around this pattern to make writing this code easier. This code becomes:

import update from 'immutability-helper';

update(myData, {
  x: {y: {z: {$set: 7}}},
  a: {b: {$push: [9]}}
});

// myData is changed here

An Introduction to Commands

An nice introduction to commands API is available in original immutability-helpers repo, which also covers how to create additional commands.

1.0.0

7 years ago

0.0.1

7 years ago