javascript - Meteor function executes before publish and subscribe finishes loading collection -
i have meteor template helper function searches document of scores. if can't find matching document, creates new 1 user. unfortunately, meteor function executes var score = userscores.findone();
before publish , subscribe functions finish. every time, new userscore document created. if turn on autopublish problem goes away , doesn't create duplicate record. how can ensure publish , subscribe functions execute first, before template helper executes?
do need place meteor method in /lib folder execute or there way client-side?
var score = userscores.findone(); if(!score) { score = { userid: meteor.userid(), total: 0, goal: 200 }; userscores.insert(score); }
the easiest way template-level subscriptions.
template.mytemplate.oncreated(function() { var subscription = this.subscribe('publicationname', publicationarguments); }
that simplified way of doing it, should have no problems helper running first.
edit: discover meteor blog has great post template-level subscriptions. highly recommend reading it: https://www.discovermeteor.com/blog/template-level-subscriptions/
Comments
Post a Comment