Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
re-mutable
Advanced tools
Re-mutable is a lightweight immutability library. There are already some excellent immutability libraries out there like immutable.js and immutability-helpers, so why reinvent the wheel? There are situations where neither are ideal:
#a) Immutable.js
#b) Immutability-helpers/React.update
#Overview For a more detailed explation, please see the wiki
Like other mutability libraries out there, Re-mutable is optimized through structural sharing; only parts of the store which are modified are cloned. Re-mutable optially also supports operation chaining to prevent unnecessary cloning between calls. Take the following example:
var update = require("re-mutable");
var state = {};
update.set(state, ["a"], 1);
update.set(state, ["b"], 2);
//console.log(state) => { a: 1, b: 2 }
//the above operations will clone the root node twice because each call is unaware of eachother. If your reducer performs
//more complicated updates to the store, it can take advantage of operation chaining to avoid these extra clones
update(state).set(["a"], 1).set(["b"], 2).end();
//this chained operation will be equivalent to the previous 2 set calls except that re-mutable will track what it has already
//cloned and not clone a second time. The notation is also more concise.
#Supported functions Re-mutable supports most common operations on your state:
var update = require("re-mutable");
var state = { x: "remove me", myarray: [0, 1, 2] };
var next = update(state)
.set(["a"], 1)
.unset(["x"])
.unset(["myarray", 1]).end();
//console.log(next); => { a: 1, myarray: [0, 2] };
var update = require("re-mutable");
var state = { myarray: [0, 1, 2] };
var next = update(state)
.push(["myarray"], 2)
.concat(["myarray"], [3, 4, 5])
.prepend(["myarray"], [-2, -1])
.sort(function (a, b) { return a > b ? -1 : 1; })
.end();
//console.log(next); => { myarray: [ 5, 4, 3, 2, 2, 1, 0, -1, -2 ] }
var update = require("re-mutable");
var state = { counts: { i: 5, j: 100 } };
var next = update(state)
.increment(["counts", "i"]) //default increment/decrement is 1
.decrement(["counts", "j"], 10) //or specify the amount to increment/decrement by, here 10
.end();
//console.log(next) => { counts: { i: 6, j: 90 } }
FAQs
A immutability library which requires minimum overhead per call
The npm package re-mutable receives a total of 49 weekly downloads. As such, re-mutable popularity was classified as not popular.
We found that re-mutable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.