user555
user555

Reputation: 1529

iron-router reloading route when session variable of subscription change

I have the following code on my iron-router waitOn hook

waitOn: function(){
            var start = Session.get("dashboardRegistrationsStart") || 0;
            var end = Session.get("dashboardRegistrationsEnd") || 20;
            return [
                this.subscribe('currentUser'),
                subs.subscribe("dashboardRegistrationsParticipants", this.params.id,start,end)
            ];
        },

Whenever I change the value of "dashboardRegistrationsStart" in the Session, the route is reloaded and the page, including the loading template, is re-rendered.

I just want to subscribe to the next records, I don't want to reload the page.

How to achieve this?

Upvotes: 3

Views: 702

Answers (1)

fabien
fabien

Reputation: 2258

You have a reactive source of data in your waitOn hook. Session.get.... Each time the value will change, the function will re-run.

You should read the documentation about the meteor tracker : http://docs.meteor.com/#/full/tracker and you should not build your application that way ; but if you have no other option, you still can wrap your function in a non reactive wraper.

It would look like that :

waitOn: function () {
    Tracker.nonreactive( function () {
        var start = Session.get( "dashboardRegistrationsStart" ) || 0;
        var end = Session.get( "dashboardRegistrationsEnd" ) || 20;
        return [
            this.subscribe( 'currentUser' ),
            subs.subscribe( "dashboardRegistrationsParticipants", this.params.id, start, end )
        ];
    } );
}

Upvotes: 1

Related Questions