npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mergestate

v1.0.4

Published

setState helper function for nested Array or Object in the state

Readme

mergeState change for nested Structure in React and Redux

setState is often nasty when you unfortunately have nested structure in your React/Redux state.
This package makes setState easy with the nested Structure.

Install

Just like other packages

  npm i --save mergestate

The s is lowercased due to my mistake and I cannot change the it. Sorry for the inconvinience.

Functions

  • mergeState(prevState, diff) This function return an new object with similar structure of prevState and with changes according to diff. prevState is not changed in the function. This function searches changes by enumerable entries of diff
  • deepSlowEqual(state1, state2, [...comparers]) This function recursively compare two objects on entries with enumerable property. [...comparers] is an array of function f(x,y) for additional rules in comparing two nodes that return true false or undefined. The comparers are called recursively when comparing each nodes in the trees. If the comparer return true or false, the deepSlowEqual will stop comparing and return true or false; when the comparer return undefined, the deepSlowEqual will continue. ...comparers could be used for ignoring certain types in comparing.

Usage as Example

This package search for changes recursively by the enumerable entries in the diff.

Assign a value in a nested Object; and Appending

import mergeState, { deepSlowEqual } from "mergeState";
import assert from "assert";

let prevState = {
  oo: { a: { b: 1 }, b: { c: 1 }, c: { d: 1 } }
};
let diff = {
  oo: { a: { b: 100, c: 99 } }
};
let state = mergeState(prevState, diff);

assert(
  deepSlowEqual(prevState, { oo: { a: { b: 1 }, b: { c: 1 }, c: { d: 1 } } })
); // prevState Unchanged
assert(deepSlowEqual(state), {
  oo: { a: { b: 100, c: 99 }, b: { c: 1 }, c: { d: 1 } }
}); // merge State by enumerable entries of diff

Assign a value in a nested Array; and Appending a value in a nested Array

import mergeState, { deepSlowEqual } from "mergeState";
import assert from "assert";

let prevState = {
  aa: [[1, 1], [1, 1], [1, 1]]
};
let diff = {
  aa: Object.assign([], { 3: [10] }, { 2: Object.assign([], { 1: 100 }) })
};
let state = mergeState(prevState, diff);

assert(deepSlowEqual(prevState, { aa: [[1, 1], [1, 1], [1, 1]] })); // prevState Unchanged
assert(deepSlowEqual(state), { aa: [[1, 1], [1, 1], [1, 100], [10]] }); // merge State by enumerable entries of diff

Assign a value in a array nested in an object

import mergeState, { deepSlowEqual } from "mergeState";
import assert from "assert";

let prevState = {
  oa: { a: [1, 1], b: [1, 1], c: [1, 1] }
};
let diff = {
  oa: { a: Object.assign([], { 1: 100 }) }
};
let state = mergeState(prevState, diff);

assert(deepSlowEqual(prevState, { oa: { a: [1, 1], b: [1, 1], c: [1, 1] } })); // prevState Unchanged
assert(deepSlowEqual(state), { oa: { a: [1, 100], b: [1, 1], c: [1, 1] } }); // merge State by enumerable entries of diff