vuejs / Discussion

Vue.js discussion
167 stars 17 forks source link

Where can I read about how computed properties work? #376

Open JosephSilber opened 9 years ago

JosephSilber commented 9 years ago

Specifically, how it calculates its dependencies:

computed: {
    foo() {
        return this.bar ? this.baz : this.boom;
    }
}

If at first this.bar is true, how does it know that foo depends on boom?

Does it re-collect its dependencies every time it runs?

dannyfritz commented 9 years ago

This looks like the function that does it to me: https://github.com/yyx990803/vue/blob/bf8e37188fc622d976ce5f2a48cdfc2c1c4e07d7/src/instance/scope.js#L215

dannyfritz commented 9 years ago

http://vuejs.org/guide/computed.html#Computed_Property_Caching

There is an example for disabling the caching if it doesn't work for your computed value:

computed: {
  example: {
    cache: false,
    get: function () {
      return Date.now() + this.msg
    }
  }
}