publish subscribe - meteor.js: understanding publishing -


i started meteor, , 1 thing still don't understand (not @ least) publishing mechanism. example, consider following code (i have disabled autopublish btw):

file: client/lib.js

var lists = new meteor.collection('list'); meteor.subscribe("categories");  template.categories.lists = function () {      return lists.find({}, {sort: {category: 1}}); }; 

file: server/lib.js:

var lists = new meteor.collection('list'); meteor.publish("categories", function() {    return lists.find({},{fields:{category:1}}); }); 

2 questions:

  • should define in every file lists collection ?
  • how meteor.subscribe("categories"); knows update lists variable ?

an other questions have following code:

file: client/lib.js:

meteor.autosubscribe(function() {     meteor.subscribe("listdetails", session.get('current_list')); }); 

file: server/lib.js:

meteor.publish("listdetails", function(category_id){    return lists.find({_id:category_id}); }); 

i assume when listdetails gets published, new list pushed current_list session. don't understand why cannot do

meteor.subscribe("listdetails", session.get('current_list')); 

furthermore, noticed these days should use deps (dependency) object. can translate example me using deps ?

thanks!

should define in every file lists collection ?

no, evaluating new meteor.collection('<name>') many times (with same <name>) gives error there collection named '<name>'. evaluate once , store in global variable.

how meteor.subscribe("categories"); knows update lists variable ?

it know how. ordinary programmer using meteor, don't need know how. @ least won't tell how, it's no secret: entire framework available on github, check code there if you're interested.

an other questions have following code:

you use meteor.subscribe("listdetails", session.get('current_list'));, subscription use value session.get('current_list') got @ moment. using deps.autorun(function() { meteor.subscribe("listdetails", session.get('current_list')); }); instead, subscription recreated each time session.get('current_list') changes (when session.set('current_list', <new-value>) evaluated).

it deps.autorun should use, meteor.autorun , meteor.autosubscribe retired.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -