Skip to content

Commit

Permalink
fix: delay proxy target evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
SunriseFox committed Nov 11, 2019
1 parent 0217be1 commit 5a8c7a9
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/utils/jss/ShadowRootPortal.tsx
Expand Up @@ -14,22 +14,25 @@ globalThis.getComputedStyle = new Proxy(globalThis.getComputedStyle || (() => {}
},
})

const proxy = new Proxy(document.body, {
get(target, key, receiver) {
const value = Reflect.get(target, key)
if (typeof value === 'function')
return function(...args: any[]) {
console.log(...args)
return Reflect.apply(value, shadow, args)
}
return value
},
set(target, key, value, receiver) {
return Reflect.set(document.body, key, value, document.body)
},
})
let proxy: HTMLElement | undefined

export function PortalShadowRoot() {
if (GetContext() === 'options') return document.body
if (!proxy)
proxy = new Proxy(document.body, {
get(target, key, receiver) {
const value = Reflect.get(target, key)
if (typeof value === 'function')
return function(...args: any[]) {
console.log(...args)
return Reflect.apply(value, shadow, args)
}
return value
},
set(target, key, value, receiver) {
return Reflect.set(document.body, key, value, document.body)
},
})
return proxy
}

Expand Down

0 comments on commit 5a8c7a9

Please sign in to comment.