mystor / meteor-routecore

Client and server side rendering/routing powered by React
84 stars 6 forks source link

waitOn equivalent #6

Closed mathieutozer closed 10 years ago

mathieutozer commented 10 years ago

In iron-router I would have done something like this to ensure my subscriptions are ready before rendering.

this.route('event', {
    path: '/event/:_id',
    waitOn: function () {
        //Meteor.subscribe('event', this.params._id);
        Meteor.subscribe('countries');
        Meteor.subscribe('players', this.params._id);
        Meteor.subscribe('votes', this.params._id);
        Meteor.subscribe('results', this.params._id);
        return Meteor.subscribe('events');
    },
    data: function () {
        var anEvent = Events.findOne(this.params._id);
        return anEvent;  
    },
    action: function() {
        if (this.ready()) {
            this.render()  
        } else {
            this.render('loading');
        }
    }
});

I've dug a bit into the documentation and the example code, and even the source, but don't see how to do this. Is this possible yet?

mystor commented 10 years ago

It IS possible, but I haven't written a nice API for it yet.

If you look at gh-release-watch, I wait on the subscription object for the unsubscribe page: https://github.com/mystor/gh-release-watch/blob/master/routes.js#L44

Basically, by calling the subscription, and then immediately asking if it is ready, you can tell whether it is ready yet, and then instead of loading a normal page, load a loading page.

At some point, I will probably add a syntax for waitOn, but I haven't gotten there yet.

mathieutozer commented 10 years ago

Thanks that works!

mystor commented 10 years ago

I think I'll mark this as closed for now, until I come up with a good mechanism to enable people to write this type of code.

The current system isn't that bad, it could use some extra documentation though.