How to wrap reactive object (with array) in custom proxy? #6443
-
In order to show users that some changes were applied to a reactive object (in a child component) I decided to pass a deep-proxy instead and set a reactive-boolean on changes. This works fine for scalar values and objects, but fails on array functions like push: Vue SFC Playground Is there a simpler[1] fix for this, or can the whole proxy be avoided[2]? [1] One possible fix would be to check if the object is an Array (Array.isArray(value)) and use VueUse's watchArray to set the reactive-boolean and return the array, instead of a custom proxy. [2] I could not find a vue way of creating a ref of a ref to watch at, because a ref of a ref won't wrap again. const x = {};
const r = ref(x);
console.log(r === ref(r)); //true |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
did you ever figure this out? I am having the same issue and just submitted #9742 |
Beta Was this translation helpful? Give feedback.
Hi, sorry for the late reply.
I came up with this and called it
stainableProxy
. It usesArray.isArray
andwatchArray
. (Date
is behaving odd as a Proxy.)