Meteor and Iron Router subscription queries

ぃ、小莉子 提交于 2019-12-13 05:24:52

问题


I found that I can just call a findOne in a global function and I'll have access to the subscription... The only thing I'm confused about is, how global a function distinguishes between collections, one subscription to the other.

// pubs

Meteor.publish("just_dob_and_id_shared_collection", function () {
  return shared_collection.find({_id: this.userId}, {fields: {'dob': 1}});
});

Meteor.publish("entire_recordset_shared_collection", function () {
  return shared_collection.find({_id: this.userId});
});

// IR controllers

fooController = RouteController.extend({
  template: 'foo-template',
  waitOn: function () {
    Meteor.subscribe("just_dob_and_id_shared_collection");
  },
...
});

barController = RouteController.extend({   
  template: 'bar-template',   
  waitOn: function () {
    Meteor.subscribe("entire_recordset_shared_collection");   }, 
... 
});

// global functions

fooFunction = function () {
  var foo = shared_collection.findOne({_id: Meteor.userId()});
  // in this case I'll have the _id and dob... this is kinda what I've tested
  // ## will be used in foo-template
}

barFunction = function () {
  var bar = shared_collection.findOne({_id: Meteor.userId()});
  // in this case maybe I'd want the entire record set to do stuff with
  // ## will be used in bar-template
}

// template helpers

Template.registerHelper("fooHelper", function () {
  fooFunction();
}

Template.registerHelper("barHelper", function () {
  barFunction();
}

// templates

<template name="foo-template">
  {{#if fooHelper}}
  ...
  {{/if}}
<template>

<template name="bar-template">
  {{#if barHelper}}
  ...
  {{/if}}
<template>

EDIT: To clarify further

I have two subscriptions, each pulling (maybe from the same record-set) different data profiles (portions of a record-set from a document within a collection).

On the client, when I do a findOne on the collection name (since I don't do it on the subscription name),

(1) which/what record-set (data profile) do I get when I call, for example the fooFunction, and why?,

(2) when does this data profile change, for example when I go to the bar-template and its subscription is called (in this case it gets all fields in the record-set, not just dob and the _id), does the recordset change when I call findOne in the fooFunction? I ask this because I'm doing a findOne on the collection, not subscription name, so in the fooFunction, theres no distinction between subscriptions. So maybe asked another way -- does the timing of the call in the fooFunction, to the collection, change the result of the findOne?

来源:https://stackoverflow.com/questions/27848634/meteor-and-iron-router-subscription-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!