FInd a reference to the child object that was changed when watching reactive complex large object #9633
Unanswered
alvinsw
asked this question in
Help/Questions
Replies: 1 comment 1 reply
-
Use watch(
() => state.someObject,
(newValue, oldValue) => {
// Note: `newValue` will be equal to `oldValue` here
// *unless* state.someObject has been replaced
},
{ deep: true }
) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When watching a nested reactive object for any changes, is it possible to get a reference to the nested part of the object that was actually changed? Is there a less well-known API or low-level API to do that?
Imagine a very large json object that is being passed on to a (child) custom component. The custom component then modify a nested value inside the object and emit an update event to signal the change. A parameter is passed to the event handler that contains only the changed part to the object instead of the whole object. The parent component then update the object, in which the change will then be reflected in the child component. Now, the very large JSON object needs to be processed in the child component (and the result is cached). So the child component needs to watch for changes to the prop. For performance reason, inside the watch callback, can we efficiently identify the actual nested part that has been changed by hooking into internal vue reactivity system?
A simple example to illustrate the problem:
parent.vue
child.vue
Beta Was this translation helpful? Give feedback.
All reactions