vue-rx icon indicating copy to clipboard operation
vue-rx copied to clipboard

Subscribing to property of computed property

Open lwansbrough opened this issue 6 years ago • 1 comments

I have the following scenario:

export default {
  name: 'Test',
  subscriptions () {
    return {
      test: this.project.test
    }
  },
  computed: {
    project () { return this.$store.getters['project/project'] }
  }
}

In this case, I have a store which produces the project object (not observable) with a test property (observable).

The problem is that if project changes, the subscription for test doesn't update to the new project.test -- so subsequent updates from the new project's test observable are not observed by the component.

How can this be addressed?

lwansbrough avatar Jan 16 '19 07:01 lwansbrough

If you want use observers irrelevant to a component’s lifecycle, use them without vuex

subscriptions is a .subscribe sugar in create lifecycle

If constantly switching between different observables is what you want, try switchMap

regou avatar Jan 16 '19 12:01 regou