Skip to content

Commit

Permalink
cache custom props on window object (#1228)
Browse files Browse the repository at this point in the history
* fix Proxy custom props issue

* set cache on window
  • Loading branch information
IzaacAyelin authored May 9, 2024
1 parent 33d23b4 commit 6f74da0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/lib/src/common/window/windowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class WindowWrapper {
}

initProxyWindow() {
const customWindowPropsSet = new Set();
const handler = {
// here the proxy target is the global window object
get: function (target, property) {
Expand All @@ -34,7 +33,6 @@ class WindowWrapper {
// here we push to the custom props Set to know later if we want to bind the prop
// reflect just assigns the proprty and returns boolean if the assign was successfull
set: function (target, property, value) {
customWindowPropsSet.add(property);
return Reflect.set(target, property, value);
},
};
Expand All @@ -43,17 +41,21 @@ class WindowWrapper {
const windowFuncHandler = {
get: function (target, property) {
if (
!customWindowPropsSet.has(property) &&
!windowProxy.proGalleryCustomProps.has(property) &&
typeof windowProxy[property] === 'function'
) {
return windowProxy[property].bind(window);
}
return windowProxy[property];
},
set: function (target, property, value) {
windowProxy.proGalleryCustomProps.add(property);
return Reflect.set(windowProxy, property, value);
},
};
if (!windowProxy.proGalleryCustomProps) {
windowProxy.proGalleryCustomProps = new Set();
}
// this second proxy that returnes binded functions to avoid issues with non configurable proprties
// eslint-disable-next-line no-undef
this.window = new Proxy({}, windowFuncHandler);
Expand Down

0 comments on commit 6f74da0

Please sign in to comment.