3.0.2 • Published 1 year ago

@indutny/sneaky-equals v3.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@indutny/sneaky-equals

Sneaky equals comparison between objects that checks only the properties that were touched.

Installation

npm install @indutny/sneaky-equals

Usage

import { wrap } from '@indutny/sneaky-equals';

const originalData = {
  nested: {
    prop: 1,
  },
  avatar: {
    src: 'image.png',
  },
};

const { proxy, changelog } = wrap(originalData);

function doSomethingWithData(data) {
  return {
    prop: data.nested.prop,
    x: data.avatar,
  };
}

const result = changelog.unwrap(doSomethingWithData(proxy));

// Prevent further access to proxy
changelog.freeze();

const sneakyEqualData = {
  nested: {
    prop: 1,
    other: 'ignored',
  },
  avatar: original.avatar,
};

console.log(changelog.isChanged(originalData, sneakyEqualData)); // false

const sneakyDifferentData = {
  nested: {
    prop: 2,
  },
  avatar: {
    ...original.avatar,
  },
};

console.log(changelog.isChanged(originalData, sneakyDifferentData)); // true

LICENSE

This software is licensed under the MIT License.

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.0.0

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago