Meteor. How to program a subscription that depends on another subscription


#1

Hi all.
I have lost so many hours/days with this issue and I still don’t know how to properly deal with it.

Let’s say I subscribe to “multisignature”
I also want to subscribe to address that depends on multisignature.

So if I write:


  mounted() {
    this.$subscribe('address', [ this.multisignature.p2sh ])
  },
  meteor: {
    address() {
      return Address.findOne( { _id: this.multisignature.p2sh } )
    },

But this doesn’t work cause when subscribing this.multisignature is not defined yet.

I have tried to $subready.multisignature to no avail.

Any general way to deal, as elegantly as possible, with this dependent subscriptions?

Thanks.


#2

What front-end package are you using?


#3

I am using Meteor - Vue.

I made it work with a non-elegant solution:

  watch: {
    '$subReady.multisig' (value) {
      if(value) {
        this.$subscribe('address', [ this.multisig.p2sh ] )
      }
    },


  meteor: {
    addr() { 
      if(!!this.multisig)
        return Address.findOne( { _id: this.multisig.p2sh }, {  } )
      return {}
    },
...

This if(!!this.multisig) made the trick.
I consider it ugly as hell.

Any other way more elegant to do it?


#4

Hey, maybe you’re looking for this package?

It let’s you send docs from multiple collections on a subscription, and setup “child” subscriptions that select based on the results of parent subscriptions.

Hey, how are you using Vue with Meteor?


#5

Thanks.

I will take a look at it.