Akryum / vue-supply

Create resources that can automatically be activated and deactivated when used (like subscriptions)
159 stars 16 forks source link

this.$subscribe is not a function (was: Meteor subscription arguments) #3

Closed gustojs closed 7 years ago

gustojs commented 7 years ago

Is it possible to provide an argument for Meteor subscription using vue-supply?

Akryum commented 7 years ago

Absolutely, follow the vue-meteor-tracker documentation for $subscribe usage.

gustojs commented 7 years ago

@Akryum thanks for the answer and sorry for disturbing, I know you're already pretty busy with all of that.

I'm using vue-meteor-tracker way to provide arguments for $subscribe, it's working fine at this end, but only as long as I don't do it in the supply Vue instance.

In particular, I am interested in the way to pass an argument from the component where I use the mixin to the subscription Vue instance, so that I have the actual value to pass to the subscription, which would come f.e. from an input field - the most common use case being a filter to search the documents with. THIS WAS SOLVED, SOLUTION IN THE NEXT COMMENT.

By the way, I tried to test your Meteor example. First thing I noticed is that the example doesn't extend Supply object. But that's an easy fix.

Then, I noticed that even if this.$subscribe works fine in my components, it is not a function in the supply activate() method.

I kind of solved it by importing VueMeteorTracker to the supply file and doing Vue.use(VueMeteorTracker) once again - this.$subscribe started working.

Sadly, it worked only until I updated Meteor to the newest 1.4.3.2 (previously I was on 1.4.2) which resulted in meteor import error coming from VueMeteorTracker. This was probably the reason for the latest fix in VueMeteorTracker, so I updated your package to the latest version too.

VueMeteorTracker 1.1.2 suddenly decided that it doesn't like to be called in the supply file anymore. If I do it, it results with Error: Can't call yield in a noYieldsAllowed block! coming from VueMeteorTracker plugin. But if I don't, I get the this.$subscribe is not a function error.

I hope that helps you somehow with potential issues. I can provide a repro if you want.

Akryum commented 7 years ago

I'll look into all that! :smile:

gustojs commented 7 years ago

Thanks.

As for the main topic, I finally realized how to do that. If I do:

mixins: [use(Items)]

I can set the filter in Items by directly changing Items.filter.

That was probably too easy to notice.

Akryum commented 7 years ago

The thing to have in mind is that a Supply is just a standard Vue instance augmented with some properties/methods.

gustojs commented 7 years ago

So the only remaining question is, how to make the Supply be aware of the this.$subscribe function.

Akryum commented 7 years ago

This should be fixed in the new vue-supply 0.2

igal1c0de4n commented 5 years ago

@gustojs you wrote:

I can set the filter in Items by directly changing Items.filter.

I'm not sure how to do that. Can you elaborate?

also, perhaps someone can explain how can I prevent the supply component from being automagically grasp'ed and activated during mixins: [use(Items)]?

In my case this happens before the calling component gets to pass the supply component the subscription arg (which it receives as a prop). The result is that the subscription is started without the necessary args (and fails)