Force Meteor To Refresh / Re-render Templates?

11,534 views
Skip to first unread message

Gage Bachik

unread,
Dec 7, 2014, 9:59:32 PM12/7/14
to meteo...@googlegroups.com

*For reference I'm using iron router.

Instead of a sign in page I have this global sign in form embedded in an nav (aka on every page). Right now I'm doing a really hacky refresh to reload the page once a user logs in.

I would like to just reload to the template aka not refresh the whole page. Basically just want the templates rendered function to rerun on login.

Here's my current login code:

'submit #login': function(event, template){
    event.preventDefault();
    var handle = template.find('#usernameLogin').value;
    var secretKey = template.find('#passwordLogin').value;
    Meteor.loginWithPassword(handle, secretKey, function(err){
        if (err) {
            alert(err);
        }else{
            $('#close').click();
            /* replace this with reactive ajax or whatever when you can! */
            Meteor._reload.reload();
        }
    });
},

Gage Bachik

unread,
Dec 8, 2014, 12:17:42 AM12/8/14
to meteo...@googlegroups.com
got it working by doing this:

Template.tournament.rendered = function () {
 
Deps.autorun(function () {
 
var self = this;
 thisCampaign
= Session.get('campaign');

don't know if that was a good way to do it though hah.

Jon James

unread,
Dec 9, 2014, 1:10:41 PM12/9/14
to meteo...@googlegroups.com
I believe you're looking for this: https://docs.meteor.com/#/full/template_autorun

From what I can tell, in your current code, the autorun will never get destroyed even after the template is destroyed. It's essentially a memory leak.

Gage Bachik

unread,
Dec 12, 2014, 3:02:31 PM12/12/14
to meteo...@googlegroups.com
Sweet that was perfect! Thank you!

Tomas Trescak

unread,
Jan 13, 2015, 11:04:34 PM1/13/15
to meteo...@googlegroups.com
Hi, how do you actually use this? Thanks!

Dirk Porsche

unread,
Jan 14, 2015, 2:59:22 AM1/14/15
to meteo...@googlegroups.com
Hi,

if this is depending on logged-in state, you could use Meteor.user() which is reactive and returns a falsey value until a user has successfully logged in. Checking this state in your template helper will result in a template refresh on change. No "autorun()" necessary.

Regards
Dirk

Dirk Porsche

unread,
Jan 14, 2015, 3:01:06 AM1/14/15
to meteo...@googlegroups.com
@Tomas Trescak, what's your use case, the context?

Regards
Dirk
Reply all
Reply to author
Forward
0 new messages