Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 634
user555 Avatar asked Dec 12 '25 21:12

user555


1 Answers

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 )
        ];
    } );
}
like image 72
fabien Avatar answered Dec 14 '25 11:12

fabien