Skip to content
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

feat(watch): deep watch allow setting condition for skipping object #12157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kimverchan
Copy link

@kimverchan kimverchan commented Oct 12, 2024

RFC: vuejs/rfcs#712

If you want to skip the dependency collection of an object when deeply watch to an object, you cannot do so currently. Add the skip attribute to watchOptions to do this. Examples are as follows:

let dummy = 0
const source = reactive({
    num1: 1,
    nested: { _skip: true, num2: 0 },
})
watch(source, () => dummy++, {
    deep: true,
    skip(val) {
      return val._skip // return true to skip val
    }
})
source.nested.num2++ // do not run callback
expect(dummy).toBe(0)
source.num1++ // run callback
expect(dummy).toBe(1)
source.nested.num2++  // do not run callback
expect(dummy).toBe(1)

@edison1105
Copy link
Member

Adding new features needs to be discussed through an RFC, similar to PR #9572.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants