Vue: Bring Vue component APIs to Vue.observables

Created on 31 Jul 2019  Â·  1Comment  Â·  Source: vuejs/vue

What problem does this feature solve?

While Vue.observables are a great way to share states (and their statically inferrable types) across components, they fall short in their lack of other features that would otherwise make them comparable to using Vuex or a new Vue bus. For example, computed properties are a really useful feature that are available in Vue instances and Vuex stores (getters), but if you want to use them with a Vue.observable, you have to construct the computed property via either of the aforementioned alternatives, instead of being able to conveniently access it from the observable itself, like you would any other property of the observable. Other features, like watchers and methods would also really come in handy

What does the proposed API look like?

const counter = Vue.observable({ count: 0 }, {
  computed: {
    square: observable => observable.count ** 2,
  },
  watch: {
    square: newVal => console.log(`the square is ${newVal}`)
  }
})

Most helpful comment

This is pretty much the function api RFC and for Vue 2 you can use https://github.com/vuejs/vue-function-api

>All comments

This is pretty much the function api RFC and for Vue 2 you can use https://github.com/vuejs/vue-function-api

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paulpflug picture paulpflug  Â·  3Comments

lmnsg picture lmnsg  Â·  3Comments

julianxhokaxhiu picture julianxhokaxhiu  Â·  3Comments

loki0609 picture loki0609  Â·  3Comments

robertleeplummerjr picture robertleeplummerjr  Â·  3Comments