Tuesday, 15 March 2011

meteor - Content wrapped in currentUser re-rendering when user updated -



meteor - Content wrapped in currentUser re-rendering when user updated -

i'm using meteor , having issue content beingness re-rendered when don't want to.

i have main content wrapped in currentuser if statement sense standard.

{{#if currentuser}} {{> content}} {{/if}}

the problem content template beingness re-rendered when update user object. there way around this? don't reference users anywhere within content template.

thank you!

here's sample app replicate problem:

html

class="lang-html prettyprint-override"><head> <title>render test</title> </head> <body> {{loginbuttons}} {{> userupdate}} {{#if currentuser}} {{> content}} {{/if}} </body> <template name="userupdate"> <p> <input id="updateuser" type="button" value="update user value" /> user lastly update: <span id="lastupdated">{{lastupdated}}</span> </p> </template> <template name="content"> <p>render count: <span id="rendercount"></span></p> </template>

javascript

class="lang-js prettyprint-override">if (meteor.isclient) { meteor.startup(function() { session.set("contentrenderedcount", 0); }); template.content.rendered = function() { var rendercount = session.get("contentrenderedcount") + 1; session.set("contentrenderedcount", rendercount); document.getelementbyid("rendercount").innertext = rendercount; }; template.userupdate.events = { "click #updateuser": function() { meteor.users.update({_id: meteor.userid()}, {$set: {lastactive: new date()}}); } }; template.userupdate.lastupdated = function() { homecoming meteor.user().lastactive; }; } if (meteor.isserver) { meteor.users.allow({ 'update': function () { homecoming true; } }); }

update: should've explained illustration little. after creating user, clicking update user value button, causes render count increment. because it's wrapped in {{#if currentuser}}. if if removed, you'll notice render count remains @ 1.

also, you'll need add together accounts-ui , accounts-password packages project.

meteor re-render template containing reactive variables altered. in case {{currentuser}} meteor.user() object containing user's data. when update users profile, object changes , tells meteor re-calculate reactive involving object.

we alter reactivity bit reacts changes in whether user logs in/out , not within object itself:

meteor.autorun(function() { session.set("meteor_loggedin",!!meteor.user()); }); handlebars.registerhelper('session',function(input){ homecoming session.get(input); });

your html

{{#if session "meteor_loggedin"}} {{> content}} {{/if}}

meteor

No comments:

Post a Comment