1.0.0 • Published 6 years ago

shallow-differs v1.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

shallow-differs (with whitelist) Build Status

This module is quite standard implementation of shallow compare of two objects. It iterates through object properties comparing them in a shallow way and returns a boolean, whether this two object are different (true) or they're the same in a shallow way (false).

One extra improvement over most basic implementation is support for a whitelist of keys, which are to be ignored during comparison. It might be useful in scenarios that we're sure that given key is not really important (think of e.g. shouldComponentUpdate and one key of props, which doesn't influence rendering but still might change and trigger unnecessary re-render).

Installation

npm install --save shallow-differs

Usage

import { shallowDiffers } from "shallow-differs";

shallowDiffers(a, b, ["keys", "to", "ignore"]);
  • arguments
    • a and b are two object, which keys we want to compare
    • whitelist is an array of keys, which will be ignored during comparison