proxy-compare
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -5,2 +5,8 @@ # Change Log | ||
## [2.3.0] - 2022-08-13 | ||
### Added | ||
- feat: support proxy-polyfill #41 | ||
### Changed | ||
- fix: cache unfreeze results #44 | ||
## [2.2.0] - 2022-06-14 | ||
@@ -7,0 +13,0 @@ ### Added |
@@ -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,i=(n,o)=>{let s=!1;const c=(t,r,o)=>{if(!s){let s=t.a.get(n);s||(s=new Set,t.a.set(n,s)),o&&s.has(e)||s.add(r)}},i={f:o,get(e,t){return t===r?n:(c(this,t),l(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)},getOwnPropertyDescriptor(e,t){return c(this,t,!0),Object.getOwnPropertyDescriptor(e,t)},ownKeys(t){return c(this,e),Reflect.ownKeys(t)}};return o&&(i.set=i.deleteProperty=()=>!1),i},a=e=>e[r]||e,l=(e,t,r)=>{if(!s(e))return e;const o=a(e),c=(e=>Object.isFrozen(e)||Object.values(Object.getOwnPropertyDescriptors(e)).some(e=>!e.writable))(o);let l=r&&r.get(o);return l&&l.f===c||(l=i(o,c),l.p=new Proxy(c?(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)})(o):o,l),r&&r.set(o,l)),l.a=t,l.c=r,l.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])},f=(t,r,n,o)=>{if(Object.is(t,r))return!1;if(!c(t)||!c(r))return!0;const s=n.get(a(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 i=null;for(const c of s){const s=c===e?u(t,r):f(t[c],r[c],n,o);if(!0!==s&&!1!==s||(i=s),i)break}return null===i&&(i=!0),o&&o.set(t,{n:r,g:i}),i},y=e=>!!s(e)&&t in e,p=e=>s(e)&&e[r]||null,g=(e,t=!0)=>{o.set(e,t)},b=(e,t)=>{const r=[],n=new WeakSet,o=(e,s)=>{if(n.has(e))return;c(e)&&n.add(e);const i=c(e)&&t.get(a(e));i?i.forEach(t=>{o(e[t],s?[...s,t]:[t])}):s&&r.push(s)};return o(e),r};export{b as affectedToPathList,l as createProxy,p as getUntracked,f as isChanged,g as markToTrack,y as trackMemo}; | ||
//# sourceMappingURL=index.modern.js.map | ||
const e=Symbol(),t=Symbol(),r=Symbol();let n=(e,t)=>new Proxy(e,t);const o=Object.getPrototypeOf,s=new WeakMap,c=e=>e&&(s.has(e)?s.get(e):o(e)===Object.prototype||o(e)===Array.prototype),l=e=>"object"==typeof e&&null!==e,a=new WeakMap,f=e=>e[r]||e,i=(s,l,p)=>{if(!c(s))return s;const y=f(s),u=(e=>Object.isFrozen(e)||Object.values(Object.getOwnPropertyDescriptors(e)).some(e=>!e.writable))(y);let g=p&&p.get(y);return g&&g[1].f===u||(g=((n,o)=>{const s={f:o};let c=!1;const l=(t,r)=>{if(!c){let o=s.a.get(n);o||(o=new Set,s.a.set(n,o)),r&&o.has(e)||o.add(t)}},a={get:(e,t)=>t===r?n:(l(t),i(e[t],s.a,s.c)),has:(e,r)=>r===t?(c=!0,s.a.delete(n),!0):(l(r),r in e),getOwnPropertyDescriptor:(e,t)=>(l(t,!0),Object.getOwnPropertyDescriptor(e,t)),ownKeys:t=>(l(e),Reflect.ownKeys(t))};return o&&(a.set=a.deleteProperty=()=>!1),[a,s]})(y,u),g[1].p=n(u?(e=>{let t=a.get(e);if(!t){if(Array.isArray(e))t=Array.from(e);else{const r=Object.getOwnPropertyDescriptors(e);Object.values(r).forEach(e=>{e.configurable=!0}),t=Object.create(o(e),r)}a.set(e,t)}return t})(y):y,g[0]),p&&p.set(y,g)),g[1].a=l,g[1].c=p,g[1].p},p=(e,t)=>{const r=Reflect.ownKeys(e),n=Reflect.ownKeys(t);return r.length!==n.length||r.some((e,t)=>e!==n[t])},y=(t,r,n,o)=>{if(Object.is(t,r))return!1;if(!l(t)||!l(r))return!0;const s=n.get(f(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 c=null;for(const l of s){const s=l===e?p(t,r):y(t[l],r[l],n,o);if(!0!==s&&!1!==s||(c=s),c)break}return null===c&&(c=!0),o&&o.set(t,{n:r,g:c}),c},u=e=>!!c(e)&&t in e,g=e=>c(e)&&e[r]||null,b=(e,t=!0)=>{s.set(e,t)},O=(e,t)=>{const r=[],n=new WeakSet,o=(e,s)=>{if(n.has(e))return;l(e)&&n.add(e);const c=l(e)&&t.get(f(e));c?c.forEach(t=>{o(e[t],s?[...s,t]:[t])}):s&&r.push(s)};return o(e),r},w=e=>{n=e};export{O as affectedToPathList,i as createProxy,g as getUntracked,y as isChanged,b as markToTrack,w as replaceNewProxy,u 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)},c=function(t){return"object"==typeof t&&null!==t},f=function(t){return t[o]||t},s=function(t,e,u){if(!a(t))return t;var c=f(t),l=function(t){return Object.isFrozen(t)||Object.values(Object.getOwnPropertyDescriptors(t)).some(function(t){return!t.writable})}(c),y=u&&u.get(c);return y&&y.f===l||((y=function(t,e){var i,u=!1,a=function(e,n,o){if(!u){var i=e.a.get(t);i||(i=new Set,e.a.set(t,i)),o&&i.has(r)||i.add(n)}},c=((i={}).f=e,i.get=function(e,r){return r===o?t:(a(this,r),s(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.getOwnPropertyDescriptor=function(t,e){return a(this,e,!0),Object.getOwnPropertyDescriptor(t,e)},i.ownKeys=function(t){return a(this,r),Reflect.ownKeys(t)},i);return e&&(c.set=c.deleteProperty=function(){return!1}),c}(c,l)).p=new Proxy(l?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)}(c):c,y),u&&u.set(c,y)),y.a=e,y.c=u,y.p},l=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)){c(o)&&n.add(o);var u=c(o)&&e.get(f(o));u?u.forEach(function(e){t(o[e],i?[].concat(i,[e]):[e])}):i&&r.push(i)}}(t),r},t.createProxy=s,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(!c(n)||!c(o))return!0;var a=i.get(f(n));if(!a)return!0;if(u){var s,y=u.get(n);if(y&&y.n===o)return y.g;u.set(n,((s={}).n=o,s.g=!1,s))}for(var p,b,d=null,g=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);!(p=g()).done;){var h=p.value,v=h===r?l(n,o):t(n[h],o[h],i,u);if(!0!==v&&!1!==v||(d=v),d)break}return null===d&&(d=!0),u&&u.set(n,((b={}).n=o,b.g=d,b)),d},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(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).proxyCompare={})}(this,function(e){function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var r=Symbol(),n=Symbol(),o=Symbol(),i=function(e,t){return new Proxy(e,t)},a=Object.getPrototypeOf,u=new WeakMap,c=function(e){return e&&(u.has(e)?u.get(e):a(e)===Object.prototype||a(e)===Array.prototype)},f=function(e){return"object"==typeof e&&null!==e},l=new WeakMap,s=function(e){return e[o]||e},y=function(e,t,u){if(!c(e))return e;var f=s(e),p=function(e){return Object.isFrozen(e)||Object.values(Object.getOwnPropertyDescriptors(e)).some(function(e){return!e.writable})}(f),b=u&&u.get(f);return b&&b[1].f===p||((b=function(e,t){var i,a=((i={}).f=t,i),u=!1,c=function(t,n){if(!u){var o=a.a.get(e);o||(o=new Set,a.a.set(e,o)),n&&o.has(r)||o.add(t)}},f={get:function(t,r){return r===o?e:(c(r),y(t[r],a.a,a.c))},has:function(t,r){return r===n?(u=!0,a.a.delete(e),!0):(c(r),r in t)},getOwnPropertyDescriptor:function(e,t){return c(t,!0),Object.getOwnPropertyDescriptor(e,t)},ownKeys:function(e){return c(r),Reflect.ownKeys(e)}};return t&&(f.set=f.deleteProperty=function(){return!1}),[f,a]}(f,p))[1].p=i(p?function(e){var t=l.get(e);if(!t){if(Array.isArray(e))t=Array.from(e);else{var r=Object.getOwnPropertyDescriptors(e);Object.values(r).forEach(function(e){e.configurable=!0}),t=Object.create(a(e),r)}l.set(e,t)}return t}(f):f,b[0]),u&&u.set(f,b)),b[1].a=t,b[1].c=u,b[1].p},p=function(e,t){var r=Reflect.ownKeys(e),n=Reflect.ownKeys(t);return r.length!==n.length||r.some(function(e,t){return e!==n[t]})};e.affectedToPathList=function(e,t){var r=[],n=new WeakSet;return function e(o,i){if(!n.has(o)){f(o)&&n.add(o);var a=f(o)&&t.get(s(o));a?a.forEach(function(t){e(o[t],i?[].concat(i,[t]):[t])}):i&&r.push(i)}}(e),r},e.createProxy=y,e.getUntracked=function(e){return c(e)&&e[o]||null},e.isChanged=function e(n,o,i,a){if(Object.is(n,o))return!1;if(!f(n)||!f(o))return!0;var u=i.get(s(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,b,d=null,g=function(e,r){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return t(e,r);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}(e))){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[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=g()).done;){var v=y.value,m=v===r?p(n,o):e(n[v],o[v],i,a);if(!0!==m&&!1!==m||(d=m),d)break}return null===d&&(d=!0),a&&a.set(n,((b={}).n=o,b.g=d,b)),d},e.markToTrack=function(e,t){void 0===t&&(t=!0),u.set(e,t)},e.replaceNewProxy=function(e){i=e},e.trackMemo=function(e){return!!c(e)&&n in e}}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -0,1 +1,2 @@ | ||
declare let newProxy: <T extends object>(target: T, handler: ProxyHandler<T>) => T; | ||
/** | ||
@@ -120,1 +121,10 @@ * Create a proxy. | ||
export declare const affectedToPathList: (obj: unknown, affected: WeakMap<object, unknown>) => (string | symbol)[][]; | ||
/** | ||
* replace newProxy function. | ||
* | ||
* This can be used if you want to use proxy-polyfill. | ||
* Note that proxy-polyfill can't polyfill everything. | ||
* Use it at your own risk. | ||
*/ | ||
export declare const replaceNewProxy: (fn: typeof newProxy) => void; | ||
export {}; |
{ | ||
"name": "proxy-compare", | ||
"description": "Compare two objects using accessed properties with Proxy", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"author": "Daishi Kato", | ||
@@ -31,3 +31,3 @@ "repository": { | ||
"compile": "microbundle build -f modern,umd", | ||
"postcompile": "cp dist/index.modern.js dist/index.modern.mjs && cp dist/index.modern.js.map dist/index.modern.mjs.map", | ||
"postcompile": "cp dist/index.modern.mjs dist/index.modern.js && cp dist/index.modern.mjs.map dist/index.modern.js.map", | ||
"test": "run-s eslint tsc-test jest", | ||
@@ -52,15 +52,15 @@ "eslint": "eslint --ext .js,.ts --ignore-pattern dist .", | ||
"devDependencies": { | ||
"@types/jest": "^28.1.1", | ||
"@typescript-eslint/eslint-plugin": "^5.28.0", | ||
"@typescript-eslint/parser": "^5.28.0", | ||
"@types/jest": "^28.1.6", | ||
"@typescript-eslint/eslint-plugin": "^5.33.0", | ||
"@typescript-eslint/parser": "^5.33.0", | ||
"documentation": "^13.2.5", | ||
"eslint": "^8.17.0", | ||
"eslint": "^8.21.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"jest": "^28.1.1", | ||
"microbundle": "^0.15.0", | ||
"jest": "^28.1.3", | ||
"microbundle": "^0.15.1", | ||
"npm-run-all": "^4.1.5", | ||
"ts-jest": "^28.0.5", | ||
"typescript": "^4.7.3" | ||
"ts-jest": "^28.0.7", | ||
"typescript": "^4.7.4" | ||
} | ||
} |
@@ -30,13 +30,11 @@ # proxy-compare | ||
> proxy = createProxy(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, b: 2 }, | ||
{ | ||
get: [Function: get], | ||
has: [Function: has], | ||
getOwnPropertyDescriptor: [Function: getOwnPropertyDescriptor], | ||
ownKeys: [Function: ownKeys] | ||
} | ||
] | ||
> proxy.a | ||
@@ -191,2 +189,14 @@ 1 | ||
### replaceNewProxy | ||
replace newProxy function. | ||
This can be used if you want to use proxy-polyfill. | ||
Note that proxy-polyfill can't polyfill everything. | ||
Use it at your own risk. | ||
#### Parameters | ||
* `fn` **any** | ||
## Projects using this library | ||
@@ -193,0 +203,0 @@ |
109
src/index.ts
@@ -14,2 +14,8 @@ // symbols | ||
// function to create a new bare proxy | ||
let newProxy = <T extends object>( | ||
target: T, | ||
handler: ProxyHandler<T>, | ||
) => new Proxy(target, handler); | ||
// get object prototype | ||
@@ -45,37 +51,44 @@ const getProto = Object.getPrototypeOf; | ||
// copy frozen object | ||
const unfreeze = (obj: object) => { | ||
if (Array.isArray(obj)) { | ||
// Arrays need a special way to copy | ||
return Array.from(obj); | ||
const unfrozenCache = new WeakMap<object, object>(); | ||
const unfreeze = <T extends object>(obj: T): T => { | ||
let unfrozen = unfrozenCache.get(obj); | ||
if (!unfrozen) { | ||
if (Array.isArray(obj)) { | ||
// Arrays need a special way to copy | ||
unfrozen = Array.from(obj); | ||
} else { | ||
// For non-array objects, we create a new object keeping the prototype | ||
// with changing all configurable options (otherwise, proxies will complain) | ||
const descriptors = Object.getOwnPropertyDescriptors(obj); | ||
Object.values(descriptors).forEach((desc) => { desc.configurable = true; }); | ||
unfrozen = Object.create(getProto(obj), descriptors); | ||
} | ||
unfrozenCache.set(obj, unfrozen as object); | ||
} | ||
// For non-array objects, we create a new object keeping the prototype | ||
// with changing all configurable options (otherwise, proxies will complain) | ||
const descriptors = Object.getOwnPropertyDescriptors(obj); | ||
Object.values(descriptors).forEach((desc) => { desc.configurable = true; }); | ||
return Object.create(getProto(obj), descriptors); | ||
return unfrozen as T; | ||
}; | ||
type Affected = WeakMap<object, Set<string | symbol>>; | ||
type ProxyCache<T extends object> = WeakMap<object, ProxyHandler<T>>; | ||
type ProxyHandler<T extends object> = { | ||
[FROZEN_PROPERTY]: boolean; | ||
type ProxyHandlerState<T extends object> = { | ||
readonly [FROZEN_PROPERTY]: boolean; | ||
[PROXY_PROPERTY]?: T; | ||
[PROXY_CACHE_PROPERTY]?: ProxyCache<object> | undefined; | ||
[AFFECTED_PROPERTY]?: Affected; | ||
get(target: T, key: string | symbol): unknown; | ||
has(target: T, key: string | symbol): boolean; | ||
getOwnPropertyDescriptor(target: T, key: string | symbol): PropertyDescriptor | undefined; | ||
ownKeys(target: T): (string | symbol)[]; | ||
set?(target: T, key: string | symbol, value: unknown): boolean; | ||
deleteProperty?(target: T, key: string | symbol): boolean; | ||
}; | ||
} | ||
type ProxyCache<T extends object> = WeakMap< | ||
object, | ||
readonly [ProxyHandler<T>, ProxyHandlerState<T>] | ||
>; | ||
const createProxyHandler = <T extends object>(origObj: T, frozen: boolean) => { | ||
const state: ProxyHandlerState<T> = { | ||
[FROZEN_PROPERTY]: frozen, | ||
}; | ||
let trackObject = false; // for trackMemo | ||
const recordUsage = (h: ProxyHandler<T>, key: string | symbol, skipWithOwnKeys?: boolean) => { | ||
const recordUsage = (key: string | symbol, skipWithOwnKeys?: boolean) => { | ||
if (!trackObject) { | ||
let used = (h[AFFECTED_PROPERTY] as Affected).get(origObj); | ||
let used = (state[AFFECTED_PROPERTY] as Affected).get(origObj); | ||
if (!used) { | ||
used = new Set(); | ||
(h[AFFECTED_PROPERTY] as Affected).set(origObj, used); | ||
(state[AFFECTED_PROPERTY] as Affected).set(origObj, used); | ||
} | ||
@@ -87,8 +100,7 @@ if (!skipWithOwnKeys || !used.has(OWN_KEYS_SYMBOL)) { | ||
}; | ||
const recordObjectAsUsed = (h: ProxyHandler<T>) => { | ||
const recordObjectAsUsed = () => { | ||
trackObject = true; | ||
(h[AFFECTED_PROPERTY] as Affected).delete(origObj); | ||
(state[AFFECTED_PROPERTY] as Affected).delete(origObj); | ||
}; | ||
const handler: ProxyHandler<T> = { | ||
[FROZEN_PROPERTY]: frozen, | ||
get(target, key) { | ||
@@ -98,7 +110,7 @@ if (key === GET_ORIGINAL_SYMBOL) { | ||
} | ||
recordUsage(this, key); | ||
recordUsage(key); | ||
return createProxy( | ||
(target as any)[key], | ||
(this[AFFECTED_PROPERTY] as Affected), | ||
this[PROXY_CACHE_PROPERTY], | ||
(state[AFFECTED_PROPERTY] as Affected), | ||
state[PROXY_CACHE_PROPERTY], | ||
); | ||
@@ -108,3 +120,3 @@ }, | ||
if (key === TRACK_MEMO_SYMBOL) { | ||
recordObjectAsUsed(this); | ||
recordObjectAsUsed(); | ||
return true; | ||
@@ -115,3 +127,3 @@ } | ||
// if `'a' in obj` is handled. | ||
recordUsage(this, key); | ||
recordUsage(key); | ||
return key in target; | ||
@@ -123,7 +135,7 @@ }, | ||
// if `obj.getOwnPropertyDescriptor('a'))` is handled. | ||
recordUsage(this, key, true); | ||
recordUsage(key, true); | ||
return Object.getOwnPropertyDescriptor(target, key); | ||
}, | ||
ownKeys(target) { | ||
recordUsage(this, OWN_KEYS_SYMBOL); | ||
recordUsage(OWN_KEYS_SYMBOL); | ||
return Reflect.ownKeys(target); | ||
@@ -135,3 +147,3 @@ }, | ||
} | ||
return handler; | ||
return [handler, state] as const; | ||
}; | ||
@@ -185,18 +197,18 @@ | ||
const frozen = isFrozen(target); | ||
let proxyHandler: ProxyHandler<typeof target> | undefined = ( | ||
let handlerAndState = ( | ||
proxyCache && (proxyCache as ProxyCache<typeof target>).get(target) | ||
); | ||
if (!proxyHandler || proxyHandler[FROZEN_PROPERTY] !== frozen) { | ||
proxyHandler = createProxyHandler<T extends object ? T : never>(target, frozen); | ||
proxyHandler[PROXY_PROPERTY] = new Proxy( | ||
if (!handlerAndState || handlerAndState[1][FROZEN_PROPERTY] !== frozen) { | ||
handlerAndState = createProxyHandler<typeof target>(target, frozen); | ||
handlerAndState[1][PROXY_PROPERTY] = newProxy( | ||
frozen ? unfreeze(target) : target, | ||
proxyHandler, | ||
) as typeof target; | ||
handlerAndState[0], | ||
); | ||
if (proxyCache) { | ||
proxyCache.set(target, proxyHandler); | ||
proxyCache.set(target, handlerAndState); | ||
} | ||
} | ||
proxyHandler[AFFECTED_PROPERTY] = affected as Affected; | ||
proxyHandler[PROXY_CACHE_PROPERTY] = proxyCache as ProxyCache<object> | undefined; | ||
return proxyHandler[PROXY_PROPERTY] as typeof target; | ||
handlerAndState[1][AFFECTED_PROPERTY] = affected as Affected; | ||
handlerAndState[1][PROXY_CACHE_PROPERTY] = proxyCache as ProxyCache<object> | undefined; | ||
return handlerAndState[1][PROXY_PROPERTY] as typeof target; | ||
}; | ||
@@ -391,1 +403,12 @@ | ||
}; | ||
/** | ||
* replace newProxy function. | ||
* | ||
* This can be used if you want to use proxy-polyfill. | ||
* Note that proxy-polyfill can't polyfill everything. | ||
* Use it at your own risk. | ||
*/ | ||
export const replaceNewProxy = (fn: typeof newProxy) => { | ||
newProxy = fn; | ||
}; |
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
89420
544
213