4.0.0 • Published 2 years ago

@indutny/sneequals v4.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@indutny/sneequals

npm size CI Status

API docs.

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

Heavily inspired by proxy-compare.

Installation

npm install @indutny/sneequals

Usage

import { watch } from '@indutny/sneequals';

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

const { proxy, watcher } = watch(originalData);

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

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

// Prevent further access to proxy
watcher.stop();

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

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

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

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

Benchmarks

On M1 Macbook Pro 13:

% npm run bench -- --duration 30 --ignore-outliers

> @indutny/sneequals@1.3.5 bench
> bencher dist/benchmarks/*.js

isChanged:    4’336’043.2 ops/sec (±28’636.7, p=0.001, o=5/100)
isNotChanged: 7’830’106.8 ops/sec (±53’241.7, p=0.001, o=1/100)
memoize:      7’632’437.7 ops/sec (±49’917.5, p=0.001, o=1/100)
watch+unwrap: 738’642.1 ops/sec (±3’396.8, p=0.001, o=3/100)

Credits

LICENSE

This software is licensed under the MIT License.

4.0.0

2 years ago

4.0.0-rc.1

2 years ago

3.2.1

2 years ago

3.2.0

3 years ago

3.1.4

3 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

3.0.0-rc.3

3 years ago

3.0.0-rc.2

3 years ago

3.0.0-rc.1

3 years ago

2.0.0

3 years ago

2.0.0-rc.4

3 years ago

2.0.0-rc.3

3 years ago

2.0.0-rc.2

3 years ago

2.0.0-rc.1

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.10

3 years ago

1.3.9

3 years ago

1.3.8

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago