Why does proxy() internally create a copy of the object? #756
-
I'm referring to this: Lines 244 to 246 in a828b04 Why does Valtio create a copy of the original object passed to cf. Vue 3's reactivity system simply wraps the Proxy over the original object. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Is it because Valtio wants to handle non-configurable, non-writable properties? FWIW, Vue 3 can't handle them because they wrap the target object directly. |
Beta Was this translation helpful? Give feedback.
-
It's the design choice. |
Beta Was this translation helpful? Give feedback.
-
I'm not fully understand about valtio but I thought that valtio is superset of const origin = {};
const proxy = new Proxy(origin, {});
proxy.x = 10;
origin.x === 10 // true From that point of view, I think using the initial object makes more sense, IMHO. |
Beta Was this translation helpful? Give feedback.
It's the design choice.
We assume the initial object as immutable objects, and do not modify it. So that
proxy()
is being a pure function.We've discussed this somewhere else, and because this behavior isn't configurable, I'm planning to change the design in the next major version: #703