e77956e4 by Adam Heath

Instead of recreating the parent proxy on each access, pass the parent

down, so the inner refs stay the same.
1 parent 2b72df6e
......@@ -343,9 +343,11 @@ const reactAttributeMap = {
class NodeProxyHandler {
#options
#cache
constructor(options = {}) {
#parent
constructor(options = {}, parent = null) {
this.#options = options
this.#cache = {}
this.#parent = parent
}
get(target, prop, receiver) {
......@@ -365,9 +367,9 @@ class NodeProxyHandler {
})) : origValue)
return newValue
case 'parent':
return this.#cache[ prop ] = proxyNode(origValue, this.#options)
return this.#parent
case 'children':
return this.#cache[ prop ] = origValue.map((child) => proxyNode(child, this.#options))
return this.#cache[ prop ] = origValue.map((child) => proxyNode(child, this.#options, this))
default:
if (typeof origValue === 'function') {
return this.#cache[ prop ] = (...args) => {
......@@ -379,8 +381,8 @@ class NodeProxyHandler {
}
}
const proxyNode = (node, options) => {
return new Proxy(node, new NodeProxyHandler(options))
const proxyNode = (node, options, parent) => {
return new Proxy(node, new NodeProxyHandler(options, parent))
}
export const parseHtml = (html: string, options): NodeType => {
......