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
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
origObj
anynextObj
anyaffected
WeakMap<object, any>cache
WeakMap<object, any>?mode
(optional, default0
)
Examples
import { isDeepChanged } from 'proxy-compare';
const objToCompare = ...;
const changed = isDeepChanged(obj, objToCompare, affected);
Returns boolean