Skip to content

watch and proxied objects #733

Closed
@fimion

Description

@fimion

So I've been doing some exploring with the composition api, watch, and reactive arrays. Since the array is wrapped in a proxy, if you attempt to use watch on the array, both the old and the new values given to you point to the proxied object and are identical.

I'd like to add a section to the watch guide about how to do proxied object comparisons. For instance, if you are wanting to compare the changes of a proxied array, you would need to provide watch a function that shallow copies the values of the array.

const myArray = reactive([1,2,3,4]);
watch(()=>[...myArray], (newVal, oldVal) =>{
   // do things...
})

also provide an example for objects.

maybe some wording about utilities that can be used to deeply copy an object/array, such as lodash.cloneDeep

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions