-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't wrap proxies in proxies #20
Conversation
aefd717
to
a945b8a
Compare
Size Change: +159 B (+3%) Total Size: 5.47 kB
|
@DAreRodz, would you mind taking a look at this change as well? |
I would copy the reference/signal instead of reproxying/duplicating the value, since this mirrors more closely the API of a regular js-object. example: const obj = {x: undefined, y: {id: 100}};
obj.x = obj.y;
obj.y.id++;
console.log(obj.x); // {id: 101} so with deepSignal it would be const obj = deepSignal({x: undefined, y: {id: 100}});
obj.x = obj.y;
obj.y.id++;
console.log(obj.x); // {id: 101} and if I would want to re-proxy I could do const obj = deepSignal({x: undefined, y: {id: 100}});
obj.x = obj.$y.value;
obj.y.id++;
console.log(obj.x); // {id: 100} or introduce an unwrap-function (see solid) const obj = deepSignal({x: undefined, y: {id: 100}});
obj.x = unwrap(obj.y);
obj.y.id++;
console.log(obj.x); // {id: 100} |
Yeah, that's how it will work after this PR is merged. Proxies and targets are linked, so reusing the proxy means reusing the target. |
aa sweet! misread the code! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM, thanks for the fix @luisherranz 😁
What
Don't wrap proxies in proxies.
Why
Because if so, copying an object creates an internal derivation of its primitive values when the signals of those values are recreated.
How
Just check if the target is a known proxy or not, and if it is, just use it as the value.