veliovgroup / jazeee-meteor-spiderable

Fork of Meteor Spiderable with longer timeout, caching, better server handling
https://atmospherejs.com/jazeee/spiderable-longer-timeout
33 stars 9 forks source link

Template-level subscriptions #33

Open natalie-natsu opened 8 years ago

natalie-natsu commented 8 years ago

Hi,

I'm having some trouble setting Meteor.isReadyForSpiderable = true; when subscriptions are defined in the template and not the route.

Paginated tables are good example of this case.

I tried to wait Template.subscriptionReady() in the Template.templateName.onCreated callback, but there's nothing concluent.

Do you have any idea ?

Here's my code:

Template.list.onCreated(function () {
    this.autorun(() => {
        if (this.subscriptionReady()) {
            Meteor.isReadyForSpiderable = true;
            console.log('ready');
        } else {
            Meteor.isReadyForSpiderable = false;
            console.log('not ready yet');
        }

        console.log(Meteor.isReadyForSpiderable);
    });
});

Thanks,

jazeee commented 8 years ago

I would think that this would work, as long as the template is the only template waiting for a subscription. If you have multiple subscriptions on the page, (which could occur with paginated tables), then you will have to wait for all of them to complete. For example:

var completedSubscriptions = {};
markSubscriptionAsReady = function(templateName){
    completedSubscriptions[templateName] = true;
    if(_.keys(completedSubscriptions).length === 2){
            Meteor.isReadyForSpiderable = true;
    }
}
Template.list.onCreated(function () {
    this.autorun(() => {
        if (this.subscriptionReady()) {
             markSubscriptionAsReady("list");
        }
    });
});
Template.someOtherTemplate.onCreated(function () {
    this.autorun(() => {
        if (this.subscriptionReady()) {
             markSubscriptionAsReady("someOtherTemplate");
        }
    });
});
dr-dimitru commented 7 years ago

Hello @WaSa42 ,

Have you solved it on your end?

natalie-natsu commented 7 years ago

Sadly no, it's been a while but I remember trying the solution that jazeee wrote behind and that it was not concluent. Maybe I did something wrong, did you try jazeee's solution too ?

nicooprat commented 7 years ago

Solved it by using this package for managing all subscriptions: https://github.com/ccorcos/meteor-subs-cache. Then you can wait for subsCache.allReady() to set Meteor.isReadyForSpiderable = true. (Note that this bug seems to be still alive https://github.com/ccorcos/meteor-subs-cache/issues/20). Pretty straightforward, and you get all the great features from SubsCache for free ;D

dr-dimitru commented 6 years ago

Hello everyone,

Shall we close this thread? //cc @mksh-su