Comment proxyInner better

This commit is contained in:
Nuckyz 2024-05-03 20:11:52 -03:00
parent 9ece4dddd3
commit ac85b3508b
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

View file

@ -53,8 +53,11 @@ export function proxyInner<T = any>(err = new Error("Proxy inner value is undefi
[proxyInnerValue]: void 0 as T | undefined
});
// Values destructured in the same tick the proxy was created will push their setInnerValue here
const recursiveSetInnerValues = [] as Array<(innerValue: T) => void>;
// Once we set the parent inner value, we will call the setInnerValue functions of the destructured values,
// for them to get the proper value from the parent and use as their inner instead
function setInnerValue(innerValue: T) {
proxyDummy[proxyInnerValue] = innerValue;
recursiveSetInnerValues.forEach(setInnerValue => setInnerValue(innerValue));
@ -72,7 +75,9 @@ export function proxyInner<T = any>(err = new Error("Proxy inner value is undefi
// `const { meow } = findByProps("meow");`
if (!isChild && isSameTick) {
const [recursiveProxy, recursiveSetInnerValue] = proxyInner(err, true);
recursiveSetInnerValues.push((innerValue: T) => {
// Set the inner value of the destructured value as the prop value p of the parent
recursiveSetInnerValue(Reflect.get(innerValue as object, p, receiver));
});