-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(watchClone): add watchClone #4794
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
base: main
Are you sure you want to change the base?
Conversation
packages/shared/watchClone/index.md
Outdated
} }, { | ||
deep: true | ||
}) |
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.
does ref()
has this option? 👀
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.
Sorry, I made a mistake. Ha ha
Thank you for your PR. I am not sure about the use cases. Could you please provide one? |
emm...because the watch api provided by vue doesn't support get the old value before the reactivity object changed, I want to provide a watch wrapper that can get the old value😀. |
what am I missing? |
I have modified your example, please take a look at it😀 |
Okay, I see your problem now. But I think there is an easy workaround for this: // vvv clone here
watch(()=>({...msg.value}),(newV, oldV)=>{
console.log(newV, oldV)
}, {
deep: true
}) |
Yours is nice, too, but wouldn't it be nice to add a wrapper like this?. Ha ha |
Okay. I think we can still improve your implementation a little: Like this we are much more flexible, and can reuse existing composalbes. |
I took your advice and refactored it and the code is much clearer, thanks! |
Before submitting the PR, please make sure you do the following
fixes #123
).Description
This PR add
watchClone
, provide a cloned old value while keeping the new value isolated when watching an object.Additional context