proxy-compare
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -5,2 +5,6 @@ # Change Log | ||
## [1.1.5] - 2021-01-20 | ||
### Changed | ||
- Fix read-only and non-configurable error (#8) | ||
## [1.1.4] - 2021-01-14 | ||
@@ -7,0 +11,0 @@ ### Changed |
@@ -1,2 +0,2 @@ | ||
const t=Symbol(),e=Symbol(),r=Symbol(),n=Object.getPrototypeOf,s=new WeakMap,o=t=>t&&(s.has(t)?s.get(t):n(t)===Object.prototype||n(t)===Array.prototype),i=t=>"object"==typeof t&&null!==t,c=n=>{const s={o:n,t:!1,r(t){if(!this.t){let e=this.a.get(this.o);e||(e=new Set,this.a.set(this.o,e)),e.add(t)}},u(){this.t=!0,this.a.delete(this.o)},get(t,e){return e===r?this.o:(this.r(e),l(t[e],this.a,this.c))},has(t,r){return r===e?(this.u(),!0):(this.r(r),r in t)},ownKeys(e){return this.r(t),Reflect.ownKeys(e)}};return Object.isFrozen(n)&&(s.set=s.deleteProperty=()=>!1),s},l=(t,e,s)=>{if(!o(t))return t;const i=t[r]||t;let l=s&&s.get(i);return l||(l=c(i),l.p=new Proxy((t=>Object.isFrozen(t)?Array.isArray(t)?Array.from(t):Object.create(n(t),(t=>{const e=Object.getOwnPropertyDescriptors(t);return Object.values(e).forEach(t=>{t.configurable=!0}),e})(t)):t)(i),l),s&&s.set(i,l)),l.a=e,l.c=s,l.p},u=(t,e)=>{const r=Reflect.ownKeys(t),n=Reflect.ownKeys(e);return r.length!==n.length||r.some((t,e)=>t!==n[e])},h=1,a=2,f=4,y=8,g=(e,r,n,s,o=0)=>{if(Object.is(e,r)&&(!i(e)||0==(2&o)))return!1;if(!i(e)||!i(r))return!0;const c=n.get(e);if(!c)return 0==(1&o);if(s&&0==(2&o)){const t=s.get(e);if(t&&t.n===r)return t.g;s.set(e,{n:r,g:!1})}let l=null;for(const i of c){const c=i===t?u(e,r):g(e[i],r[i],n,s,o>>>2<<2|o>>>2);if(!0!==c&&!1!==c||(l=c),l)break}return null===l&&(l=0==(1&o)),s&&0==(2&o)&&s.set(e,{n:r,g:l}),l},b=t=>!!o(t)&&e in t,p=t=>o(t)&&t[r]||null,O=(t,e=!0)=>{s.set(t,e)},j=(t,e)=>{const r=[],n=(t,s)=>{const o=e.get(t);o?o.forEach(e=>{n(t[e],s?[...s,e]:[e])}):s&&r.push(s)};return n(t),r};export{h as MODE_ASSUME_UNCHANGED_IF_UNAFFECTED,f as MODE_ASSUME_UNCHANGED_IF_UNAFFECTED_IN_DEEP,a as MODE_IGNORE_REF_EQUALITY,y as MODE_IGNORE_REF_EQUALITY_IN_DEEP,j as affectedToPathList,l as createDeepProxy,p as getUntrackedObject,g as isDeepChanged,O as markToTrack,b as trackMemo}; | ||
const t=Symbol(),e=Symbol(),r=Symbol(),n=Object.getPrototypeOf,s=new WeakMap,o=t=>t&&(s.has(t)?s.get(t):n(t)===Object.prototype||n(t)===Array.prototype),i=t=>"object"==typeof t&&null!==t,c=n=>{const s={o:n,t:!1,r(t){if(!this.t){let e=this.a.get(this.o);e||(e=new Set,this.a.set(this.o,e)),e.add(t)}},u(){this.t=!0,this.a.delete(this.o)},get(t,e){return e===r?this.o:(this.r(e),l(t[e],this.a,this.c))},has(t,r){return r===e?(this.u(),!0):(this.r(r),r in t)},ownKeys(e){return this.r(t),Reflect.ownKeys(e)}};return Object.isFrozen(n)&&(s.set=s.deleteProperty=()=>!1),s},l=(t,e,s)=>{if(!o(t))return t;const i=t[r]||t;let l=s&&s.get(i);return l||(l=c(i),l.p=new Proxy((t=>{const e=Object.getOwnPropertyDescriptors(t),r=Object.values(e);return!Object.isFrozen(t)&&r.every(t=>t.writable)?t:Array.isArray(t)?Array.from(t):(r.forEach(t=>{t.configurable=!0}),Object.create(n(t),e))})(i),l),s&&s.set(i,l)),l.a=e,l.c=s,l.p},u=(t,e)=>{const r=Reflect.ownKeys(t),n=Reflect.ownKeys(e);return r.length!==n.length||r.some((t,e)=>t!==n[e])},h=1,a=2,f=4,y=8,b=(e,r,n,s,o=0)=>{if(Object.is(e,r)&&(!i(e)||0==(2&o)))return!1;if(!i(e)||!i(r))return!0;const c=n.get(e);if(!c)return 0==(1&o);if(s&&0==(2&o)){const t=s.get(e);if(t&&t.n===r)return t.g;s.set(e,{n:r,g:!1})}let l=null;for(const i of c){const c=i===t?u(e,r):b(e[i],r[i],n,s,o>>>2<<2|o>>>2);if(!0!==c&&!1!==c||(l=c),l)break}return null===l&&(l=0==(1&o)),s&&0==(2&o)&&s.set(e,{n:r,g:l}),l},g=t=>!!o(t)&&e in t,p=t=>o(t)&&t[r]||null,O=(t,e=!0)=>{s.set(t,e)},j=(t,e)=>{const r=[],n=(t,s)=>{const o=e.get(t);o?o.forEach(e=>{n(t[e],s?[...s,e]:[e])}):s&&r.push(s)};return n(t),r};export{h as MODE_ASSUME_UNCHANGED_IF_UNAFFECTED,f as MODE_ASSUME_UNCHANGED_IF_UNAFFECTED_IN_DEEP,a as MODE_IGNORE_REF_EQUALITY,y as MODE_IGNORE_REF_EQUALITY_IN_DEEP,j as affectedToPathList,l as createDeepProxy,p as getUntrackedObject,b as isDeepChanged,O as markToTrack,g as trackMemo}; | ||
//# sourceMappingURL=index.modern.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).proxyCompare={})}(this,function(t){function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var r=Symbol(),n=Symbol(),o=Symbol(),i=Object.getPrototypeOf,u=new WeakMap,a=function(t){return t&&(u.has(t)?u.get(t):i(t)===Object.prototype||i(t)===Array.prototype)},f=function(t){return"object"==typeof t&&null!==t},c=function(t,e,u){if(!a(t))return t;var f,s,l,y=t[o]||t,h=u&&u.get(y);return h||((f=y,(s={}).o=f,s.t=!1,s.r=function(t){if(!this.t){var e=this.a.get(this.o);e||(e=new Set,this.a.set(this.o,e)),e.add(t)}},s.u=function(){this.t=!0,this.a.delete(this.o)},s.get=function(t,e){return e===o?this.o:(this.r(e),c(t[e],this.a,this.c))},s.has=function(t,e){return e===n?(this.u(),!0):(this.r(e),e in t)},s.ownKeys=function(t){return this.r(r),Reflect.ownKeys(t)},l=s,Object.isFrozen(f)&&(l.set=l.deleteProperty=function(){return!1}),h=l).p=new Proxy(function(t){return Object.isFrozen(t)?Array.isArray(t)?Array.from(t):Object.create(i(t),function(t){var e=Object.getOwnPropertyDescriptors(t);return Object.values(e).forEach(function(t){t.configurable=!0}),e}(t)):t}(y),h),u&&u.set(y,h)),h.a=e,h.c=u,h.p},s=function(t,e){var r=Reflect.ownKeys(t),n=Reflect.ownKeys(e);return r.length!==n.length||r.some(function(t,e){return t!==n[e]})};t.MODE_ASSUME_UNCHANGED_IF_UNAFFECTED=1,t.MODE_ASSUME_UNCHANGED_IF_UNAFFECTED_IN_DEEP=4,t.MODE_IGNORE_REF_EQUALITY=2,t.MODE_IGNORE_REF_EQUALITY_IN_DEEP=8,t.affectedToPathList=function(t,e){var r=[];return function t(n,o){var i=e.get(n);i?i.forEach(function(e){t(n[e],o?[].concat(o,[e]):[e])}):o&&r.push(o)}(t),r},t.createDeepProxy=c,t.getUntrackedObject=function(t){return a(t)&&t[o]||null},t.isDeepChanged=function t(n,o,i,u,a){if(void 0===a&&(a=0),Object.is(n,o)&&(!f(n)||0==(2&a)))return!1;if(!f(n)||!f(o))return!0;var c=i.get(n);if(!c)return 0==(1&a);if(u&&0==(2&a)){var l,y=u.get(n);if(y&&y.n===o)return y.g;u.set(n,((l={}).n=o,l.g=!1,l))}for(var h,p,b=null,d=function(t,r){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,r){if(t){if("string"==typeof t)return e(t,r);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,r):void 0}}(t))){n&&(t=n);var o=0;return function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}(c);!(h=d()).done;){var g=h.value,E=g===r?s(n,o):t(n[g],o[g],i,u,a>>>2<<2|a>>>2);if(!0!==E&&!1!==E||(b=E),b)break}return null===b&&(b=0==(1&a)),u&&0==(2&a)&&u.set(n,((p={}).n=o,p.g=b,p)),b},t.markToTrack=function(t,e){void 0===e&&(e=!0),u.set(t,e)},t.trackMemo=function(t){return!!a(t)&&n in t}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t||self).proxyCompare={})}(this,function(t){function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var r=Symbol(),n=Symbol(),o=Symbol(),i=Object.getPrototypeOf,u=new WeakMap,a=function(t){return t&&(u.has(t)?u.get(t):i(t)===Object.prototype||i(t)===Array.prototype)},f=function(t){return"object"==typeof t&&null!==t},c=function(t,e,u){if(!a(t))return t;var f,s,l,y=t[o]||t,h=u&&u.get(y);return h||((f=y,(s={}).o=f,s.t=!1,s.r=function(t){if(!this.t){var e=this.a.get(this.o);e||(e=new Set,this.a.set(this.o,e)),e.add(t)}},s.u=function(){this.t=!0,this.a.delete(this.o)},s.get=function(t,e){return e===o?this.o:(this.r(e),c(t[e],this.a,this.c))},s.has=function(t,e){return e===n?(this.u(),!0):(this.r(e),e in t)},s.ownKeys=function(t){return this.r(r),Reflect.ownKeys(t)},l=s,Object.isFrozen(f)&&(l.set=l.deleteProperty=function(){return!1}),h=l).p=new Proxy(function(t){var e=Object.getOwnPropertyDescriptors(t),r=Object.values(e);return!Object.isFrozen(t)&&r.every(function(t){return t.writable})?t:Array.isArray(t)?Array.from(t):(r.forEach(function(t){t.configurable=!0}),Object.create(i(t),e))}(y),h),u&&u.set(y,h)),h.a=e,h.c=u,h.p},s=function(t,e){var r=Reflect.ownKeys(t),n=Reflect.ownKeys(e);return r.length!==n.length||r.some(function(t,e){return t!==n[e]})};t.MODE_ASSUME_UNCHANGED_IF_UNAFFECTED=1,t.MODE_ASSUME_UNCHANGED_IF_UNAFFECTED_IN_DEEP=4,t.MODE_IGNORE_REF_EQUALITY=2,t.MODE_IGNORE_REF_EQUALITY_IN_DEEP=8,t.affectedToPathList=function(t,e){var r=[];return function t(n,o){var i=e.get(n);i?i.forEach(function(e){t(n[e],o?[].concat(o,[e]):[e])}):o&&r.push(o)}(t),r},t.createDeepProxy=c,t.getUntrackedObject=function(t){return a(t)&&t[o]||null},t.isDeepChanged=function t(n,o,i,u,a){if(void 0===a&&(a=0),Object.is(n,o)&&(!f(n)||0==(2&a)))return!1;if(!f(n)||!f(o))return!0;var c=i.get(n);if(!c)return 0==(1&a);if(u&&0==(2&a)){var l,y=u.get(n);if(y&&y.n===o)return y.g;u.set(n,((l={}).n=o,l.g=!1,l))}for(var h,p,b=null,d=function(t,r){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,r){if(t){if("string"==typeof t)return e(t,r);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,r):void 0}}(t))){n&&(t=n);var o=0;return function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}(c);!(h=d()).done;){var g=h.value,E=g===r?s(n,o):t(n[g],o[g],i,u,a>>>2<<2|a>>>2);if(!0!==E&&!1!==E||(b=E),b)break}return null===b&&(b=0==(1&a)),u&&0==(2&a)&&u.set(n,((p={}).n=o,p.g=b,p)),b},t.markToTrack=function(t,e){void 0===e&&(e=!0),u.set(t,e)},t.trackMemo=function(t){return!!a(t)&&n in t}}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "proxy-compare", | ||
"description": "Compare two objects using accessed properties with Proxy", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"author": "Daishi Kato", | ||
@@ -38,6 +38,6 @@ "repository": { | ||
"@types/jest": "^26.0.20", | ||
"@typescript-eslint/eslint-plugin": "^4.13.0", | ||
"@typescript-eslint/parser": "^4.13.0", | ||
"documentation": "^13.1.0", | ||
"eslint": "^7.17.0", | ||
"@typescript-eslint/eslint-plugin": "^4.14.0", | ||
"@typescript-eslint/parser": "^4.14.0", | ||
"documentation": "^13.1.1", | ||
"eslint": "^7.18.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
@@ -44,0 +44,0 @@ "eslint-plugin-import": "^2.22.1", |
@@ -35,17 +35,24 @@ // symbols | ||
const getPropDescs = (obj: object) => { | ||
// copy obj if frozen | ||
const unfreeze = (obj: object) => { | ||
// Object.isFrozen() doesn't detect non-writable properties | ||
// See: https://github.com/dai-shi/proxy-compare/pull/8 | ||
const descriptors = Object.getOwnPropertyDescriptors(obj); | ||
Object.values(descriptors).forEach((descriptor) => { | ||
descriptor.configurable = true; | ||
}); | ||
return descriptors; | ||
const descs = Object.values(descriptors); | ||
if (!Object.isFrozen(obj) && descs.every((desc) => desc.writable)) { | ||
// Not frozen, so return as is | ||
return obj; | ||
} | ||
// We need to copy the object | ||
if (Array.isArray(obj)) { | ||
// Arrays need a special way to copy | ||
return Array.from(obj); | ||
} | ||
// For non-array objects, we create a new object keeping the prototype | ||
// with changing all configurable options (otherwise, proxies will complain) | ||
descs.forEach((desc) => { desc.configurable = true; }); | ||
return Object.create(getProto(obj), descriptors); | ||
}; | ||
// copy obj if frozen | ||
const unfreeze = (obj: object) => ( | ||
!Object.isFrozen(obj) ? obj | ||
: Array.isArray(obj) ? Array.from(obj) | ||
: /* otherwise */ Object.create(getProto(obj), getPropDescs(obj)) | ||
); | ||
type Affected = WeakMap<object, Set<string | number | symbol>>; | ||
@@ -52,0 +59,0 @@ type ProxyCache<T extends object> = WeakMap<object, ProxyHandler<T>>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48589
322