proxy-compare
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -5,2 +5,6 @@ # Change Log | ||
## [2.0.3] - 2022-02-28 | ||
### Changed | ||
- Fix affectedToPathList to avoid maximum call stack size exceeded error (#32) | ||
## [2.0.2] - 2021-08-13 | ||
@@ -7,0 +11,0 @@ ### Changed |
@@ -1,2 +0,2 @@ | ||
const e=Symbol(),t=Symbol(),r=Symbol(),n=Object.getPrototypeOf,o=new WeakMap,s=e=>e&&(o.has(e)?o.get(e):n(e)===Object.prototype||n(e)===Array.prototype),c=e=>"object"==typeof e&&null!==e,l=(n,o)=>{let s=!1;const c=(e,t)=>{if(!s){let r=e.a.get(n);r||(r=new Set,e.a.set(n,r)),r.add(t)}},l={f:o,get(e,t){return t===r?n:(c(this,t),i(e[t],this.a,this.c))},has(e,r){return r===t?(s=!0,this.a.delete(n),!0):(c(this,r),r in e)},ownKeys(t){return c(this,e),Reflect.ownKeys(t)}};return o&&(l.set=l.deleteProperty=()=>!1),l},i=(e,t,o)=>{if(!s(e))return e;const c=e[r]||e,i=(e=>Object.isFrozen(e)||Object.values(Object.getOwnPropertyDescriptors(e)).some(e=>!e.writable))(c);let u=o&&o.get(c);return u&&u.f===i||(u=l(c,i),u.p=new Proxy(i?(e=>{if(Array.isArray(e))return Array.from(e);const t=Object.getOwnPropertyDescriptors(e);return Object.values(t).forEach(e=>{e.configurable=!0}),Object.create(n(e),t)})(c):c,u),o&&o.set(c,u)),u.a=t,u.c=o,u.p},u=(e,t)=>{const r=Reflect.ownKeys(e),n=Reflect.ownKeys(t);return r.length!==n.length||r.some((e,t)=>e!==n[t])},a=(t,r,n,o)=>{if(Object.is(t,r))return!1;if(!c(t)||!c(r))return!0;const s=n.get(t);if(!s)return!0;if(o){const e=o.get(t);if(e&&e.n===r)return e.g;o.set(t,{n:r,g:!1})}let l=null;for(const c of s){const s=c===e?u(t,r):a(t[c],r[c],n,o);if(!0!==s&&!1!==s||(l=s),l)break}return null===l&&(l=!0),o&&o.set(t,{n:r,g:l}),l},f=e=>!!s(e)&&t in e,y=e=>s(e)&&e[r]||null,b=(e,t=!0)=>{o.set(e,t)},g=(e,t)=>{const r=[],n=(e,o)=>{const s=t.get(e);s?s.forEach(t=>{n(e[t],o?[...o,t]:[t])}):o&&r.push(o)};return n(e),r};export{g as affectedToPathList,i as createProxy,y as getUntracked,a as isChanged,b as markToTrack,f as trackMemo}; | ||
const e=Symbol(),t=Symbol(),r=Symbol(),n=Object.getPrototypeOf,o=new WeakMap,s=e=>e&&(o.has(e)?o.get(e):n(e)===Object.prototype||n(e)===Array.prototype),c=e=>"object"==typeof e&&null!==e,l=(n,o)=>{let s=!1;const c=(e,t)=>{if(!s){let r=e.a.get(n);r||(r=new Set,e.a.set(n,r)),r.add(t)}},l={f:o,get(e,t){return t===r?n:(c(this,t),a(e[t],this.a,this.c))},has(e,r){return r===t?(s=!0,this.a.delete(n),!0):(c(this,r),r in e)},ownKeys(t){return c(this,e),Reflect.ownKeys(t)}};return o&&(l.set=l.deleteProperty=()=>!1),l},a=(e,t,o)=>{if(!s(e))return e;const c=e[r]||e,a=(e=>Object.isFrozen(e)||Object.values(Object.getOwnPropertyDescriptors(e)).some(e=>!e.writable))(c);let i=o&&o.get(c);return i&&i.f===a||(i=l(c,a),i.p=new Proxy(a?(e=>{if(Array.isArray(e))return Array.from(e);const t=Object.getOwnPropertyDescriptors(e);return Object.values(t).forEach(e=>{e.configurable=!0}),Object.create(n(e),t)})(c):c,i),o&&o.set(c,i)),i.a=t,i.c=o,i.p},i=(e,t)=>{const r=Reflect.ownKeys(e),n=Reflect.ownKeys(t);return r.length!==n.length||r.some((e,t)=>e!==n[t])},u=(t,r,n,o)=>{if(Object.is(t,r))return!1;if(!c(t)||!c(r))return!0;const s=n.get(t);if(!s)return!0;if(o){const e=o.get(t);if(e&&e.n===r)return e.g;o.set(t,{n:r,g:!1})}let l=null;for(const c of s){const s=c===e?i(t,r):u(t[c],r[c],n,o);if(!0!==s&&!1!==s||(l=s),l)break}return null===l&&(l=!0),o&&o.set(t,{n:r,g:l}),l},f=e=>!!s(e)&&t in e,y=e=>s(e)&&e[r]||null,b=(e,t=!0)=>{o.set(e,t)},g=(e,t)=>{const r=[],n=new WeakSet,o=(e,s)=>{if(n.has(e))return;c(e)&&n.add(e);const l=t.get(e);l?l.forEach(t=>{o(e[t],s?[...s,t]:[t])}):s&&r.push(s)};return o(e),r};export{g as affectedToPathList,a as createProxy,y as getUntracked,u as isChanged,b as markToTrack,f as trackMemo}; | ||
//# sourceMappingURL=index.modern.mjs.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=t[o]||t,s=function(t){return Object.isFrozen(t)||Object.values(Object.getOwnPropertyDescriptors(t)).some(function(t){return!t.writable})}(f),l=u&&u.get(f);return l&&l.f===s||((l=function(t,e){var i,u=!1,a=function(e,r){if(!u){var n=e.a.get(t);n||(n=new Set,e.a.set(t,n)),n.add(r)}},f=((i={}).f=e,i.get=function(e,r){return r===o?t:(a(this,r),c(e[r],this.a,this.c))},i.has=function(e,r){return r===n?(u=!0,this.a.delete(t),!0):(a(this,r),r in e)},i.ownKeys=function(t){return a(this,r),Reflect.ownKeys(t)},i);return e&&(f.set=f.deleteProperty=function(){return!1}),f}(f,s)).p=new Proxy(s?function(t){if(Array.isArray(t))return Array.from(t);var e=Object.getOwnPropertyDescriptors(t);return Object.values(e).forEach(function(t){t.configurable=!0}),Object.create(i(t),e)}(f):f,l),u&&u.set(f,l)),l.a=e,l.c=u,l.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.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.createProxy=c,t.getUntracked=function(t){return a(t)&&t[o]||null},t.isChanged=function t(n,o,i,u){if(Object.is(n,o))return!1;if(!f(n)||!f(o))return!0;var a=i.get(n);if(!a)return!0;if(u){var c,l=u.get(n);if(l&&l.n===o)return l.g;u.set(n,((c={}).n=o,c.g=!1,c))}for(var y,p,b=null,d=function(t,r){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);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.")}(a);!(y=d()).done;){var g=y.value,h=g===r?s(n,o):t(n[g],o[g],i,u);if(!0!==h&&!1!==h||(b=h),b)break}return null===b&&(b=!0),u&&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,a=new WeakMap,u=function(t){return t&&(a.has(t)?a.get(t):i(t)===Object.prototype||i(t)===Array.prototype)},f=function(t){return"object"==typeof t&&null!==t},c=function(t,e,a){if(!u(t))return t;var f=t[o]||t,s=function(t){return Object.isFrozen(t)||Object.values(Object.getOwnPropertyDescriptors(t)).some(function(t){return!t.writable})}(f),l=a&&a.get(f);return l&&l.f===s||((l=function(t,e){var i,a=!1,u=function(e,r){if(!a){var n=e.a.get(t);n||(n=new Set,e.a.set(t,n)),n.add(r)}},f=((i={}).f=e,i.get=function(e,r){return r===o?t:(u(this,r),c(e[r],this.a,this.c))},i.has=function(e,r){return r===n?(a=!0,this.a.delete(t),!0):(u(this,r),r in e)},i.ownKeys=function(t){return u(this,r),Reflect.ownKeys(t)},i);return e&&(f.set=f.deleteProperty=function(){return!1}),f}(f,s)).p=new Proxy(s?function(t){if(Array.isArray(t))return Array.from(t);var e=Object.getOwnPropertyDescriptors(t);return Object.values(e).forEach(function(t){t.configurable=!0}),Object.create(i(t),e)}(f):f,l),a&&a.set(f,l)),l.a=e,l.c=a,l.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.affectedToPathList=function(t,e){var r=[],n=new WeakSet;return function t(o,i){if(!n.has(o)){f(o)&&n.add(o);var a=e.get(o);a?a.forEach(function(e){t(o[e],i?[].concat(i,[e]):[e])}):i&&r.push(i)}}(t),r},t.createProxy=c,t.getUntracked=function(t){return u(t)&&t[o]||null},t.isChanged=function t(n,o,i,a){if(Object.is(n,o))return!1;if(!f(n)||!f(o))return!0;var u=i.get(n);if(!u)return!0;if(a){var c,l=a.get(n);if(l&&l.n===o)return l.g;a.set(n,((c={}).n=o,c.g=!1,c))}for(var y,p,d=null,b=function(t,r){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);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.")}(u);!(y=b()).done;){var g=y.value,h=g===r?s(n,o):t(n[g],o[g],i,a);if(!0!==h&&!1!==h||(d=h),d)break}return null===d&&(d=!0),a&&a.set(n,((p={}).n=o,p.g=d,p)),d},t.markToTrack=function(t,e){void 0===e&&(e=!0),a.set(t,e)},t.trackMemo=function(t){return!!u(t)&&n in t}}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "proxy-compare", | ||
"description": "Compare two objects using accessed properties with Proxy", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"author": "Daishi Kato", | ||
@@ -48,15 +48,15 @@ "repository": { | ||
"devDependencies": { | ||
"@types/jest": "^27.0.0", | ||
"@typescript-eslint/eslint-plugin": "^4.29.1", | ||
"@typescript-eslint/parser": "^4.29.1", | ||
"@types/jest": "^27.4.1", | ||
"@typescript-eslint/eslint-plugin": "^5.12.1", | ||
"@typescript-eslint/parser": "^5.12.1", | ||
"documentation": "^13.2.5", | ||
"eslint": "^7.32.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
"eslint-plugin-import": "^2.24.0", | ||
"jest": "^27.0.6", | ||
"microbundle": "^0.13.3", | ||
"eslint": "^8.10.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-plugin-import": "^2.25.4", | ||
"jest": "^27.5.1", | ||
"microbundle": "^0.14.2", | ||
"npm-run-all": "^4.1.5", | ||
"ts-jest": "^27.0.4", | ||
"typescript": "^4.3.5" | ||
"ts-jest": "^27.1.3", | ||
"typescript": "^4.5.5" | ||
} | ||
} |
@@ -348,3 +348,11 @@ // symbols | ||
const list: (string | symbol)[][] = []; | ||
const seen = new WeakSet(); | ||
const walk = (x: unknown, path?: (string | symbol)[]) => { | ||
if (seen.has(x as object)) { | ||
// for object with cycles | ||
return; | ||
} | ||
if (isObject(x)) { | ||
seen.add(x); | ||
} | ||
const used = (affected as Affected).get(x as object); | ||
@@ -351,0 +359,0 @@ if (used) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
82274
498