JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1280056
  • Score
    100M100P100Q187278F
  • License MIT

Compare two objects using accessed properties with Proxy

Package Exports

  • proxy-compare

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (proxy-compare) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

proxy-compare

CI npm size

Compare two objects using accessed properties with Proxy

Introduction

This is an internal library used in React Tracked.

Install

npm install proxy-compare

Usage

$ node
> const { createDeepProxy, isDeepChanged } = require('proxy-compare')
undefined
> state = { a: 1, b: 2 }
{ a: 1, b: 2 }
> affected = new WeakMap()
WeakMap { [items unknown] }
> proxy = createDeepProxy(state, affected)
Proxy [ { a: 1, b: 2 },
  { r: [Function],
    u: [Function],
    get: [Function],
    has: [Function],
    ownKeys: [Function],
    p: Proxy [ [Object], [Circular] ],
    o: { a: 1, b: 2 },
    t: false,
    a: WeakMap { [items unknown] },
    c: undefined } ]
> proxy.a
1
> isDeepChanged(state, { a: 1, b: 22 }, affected)
false
> isDeepChanged(state, { a: 11, b: 2 }, affected)
true

API

createDeepProxy

create a proxy

It will recursively create a proxy upon access.

Parameters

Examples

import { createDeepProxy } from 'proxy-compare';

const obj = ...;
const affected = new WeakMap();
const proxy = createDeepProxy(obj, affected);

Returns T

isDeepChanged

compare two object

It will compare only with affected object properties

Parameters

Examples

import { isDeepChanged } from 'proxy-compare';

const objToCompare = ...;
const changed = isDeepChanged(obj, objToCompare, affected);

Returns boolean

Projects using this library

Similar libraries