Instead of recreating the parent proxy on each access, pass the parent
down, so the inner refs stay the same.
Showing
1 changed file
with
7 additions
and
5 deletions
... | @@ -343,9 +343,11 @@ const reactAttributeMap = { | ... | @@ -343,9 +343,11 @@ const reactAttributeMap = { |
343 | class NodeProxyHandler { | 343 | class NodeProxyHandler { |
344 | #options | 344 | #options |
345 | #cache | 345 | #cache |
346 | constructor(options = {}) { | 346 | #parent |
347 | constructor(options = {}, parent = null) { | ||
347 | this.#options = options | 348 | this.#options = options |
348 | this.#cache = {} | 349 | this.#cache = {} |
350 | this.#parent = parent | ||
349 | } | 351 | } |
350 | 352 | ||
351 | get(target, prop, receiver) { | 353 | get(target, prop, receiver) { |
... | @@ -365,9 +367,9 @@ class NodeProxyHandler { | ... | @@ -365,9 +367,9 @@ class NodeProxyHandler { |
365 | })) : origValue) | 367 | })) : origValue) |
366 | return newValue | 368 | return newValue |
367 | case 'parent': | 369 | case 'parent': |
368 | return this.#cache[ prop ] = proxyNode(origValue, this.#options) | 370 | return this.#parent |
369 | case 'children': | 371 | case 'children': |
370 | return this.#cache[ prop ] = origValue.map((child) => proxyNode(child, this.#options)) | 372 | return this.#cache[ prop ] = origValue.map((child) => proxyNode(child, this.#options, this)) |
371 | default: | 373 | default: |
372 | if (typeof origValue === 'function') { | 374 | if (typeof origValue === 'function') { |
373 | return this.#cache[ prop ] = (...args) => { | 375 | return this.#cache[ prop ] = (...args) => { |
... | @@ -379,8 +381,8 @@ class NodeProxyHandler { | ... | @@ -379,8 +381,8 @@ class NodeProxyHandler { |
379 | } | 381 | } |
380 | } | 382 | } |
381 | 383 | ||
382 | const proxyNode = (node, options) => { | 384 | const proxyNode = (node, options, parent) => { |
383 | return new Proxy(node, new NodeProxyHandler(options)) | 385 | return new Proxy(node, new NodeProxyHandler(options, parent)) |
384 | } | 386 | } |
385 | 387 | ||
386 | export const parseHtml = (html: string, options): NodeType => { | 388 | export const parseHtml = (html: string, options): NodeType => { | ... | ... |
-
Please register or sign in to post a comment