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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -