Skip to content

Watchers breaking computed property #38

Closed
@paulschwoerer

Description

@paulschwoerer

I might have found an issue when using watchers on computed properties including meteor data.
To illustrate, take the following example (using the VueMeteor demo app):

In the Notes.vue Component we'll be adding a watcher for the firstNote() computed property.

watch: {
  firstNote(val) {
    console.log(val)
  }
}

After adding the watcher, the computed property will not compute, as this.notes is undefined in the computed property for some reason.

The same can be observed for another another example:

computed: {
  notesCount() {
    return this.notes ? this.notes.length : -1;
  }
}

This computed property will compute just fine, but as soon as we add a watcher to observe changes in the item count, it will break, meaning it will not recompute and always show -1.

watch: {
  notesCount(value) {
    console.log(value)
  }
}

This behavior can be fixed with the following:

computed: {
  notesCount() {
    return this.$subReady.notes ? this.notes.length : -1;
  }
}

Using this computed property, the code will behave as expected, updating the count of items and printing it to the console through the watcher whenever it changes.
Maybe this is something to look into as I think the first example should behave in the same way as the latter.

This issue might be related to #34.

Reproducing example repo https://github.com/paulschwoerer/meteor-vue-tracker-watcher-error-example

Cheers!

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