I would like to have access to the Subscription handle associated with the Meteor.users collection the same as if I had done Meteor.subscribe('users').
The reason is that I want to be able to check the .ready() property of the subscription handle to know when the users collection has been synced on startup in a clean way. Sure you can do {{#if currentUser}}, etc. but that's really not good enough to do control flow in a complex app. I can't have all my routing logic in templates.
Since the users collection is autopublished to the client by the accounts-base package I don't see a way to get a handle, because even if I did an additional
client: handle = Meteor.subscribe('myUsers'); handle.ready() ?
server: Meteor.publish('myUsers', function(){ return some users });
that doesn't guarantee the built-in subscription is ready even though it's a reasonable assumption.
Thoughts?
The relevant code is in /packages/accounts-base/accounts_server.js:
~~~~~
// Publish the current user's record to the client.
Meteor.publish(null, function() {
if (this.userId) {
return Meteor.users.find(
{_id: this.userId},
{fields: {profile: 1, username: 1, emails: 1}});
} else {
return null;
}
}, /*suppress autopublish warning*/{is_auto: true});
...
Meteor.default_server.publish(null, function () {
if (this.userId) {
return Meteor.users.find(
{_id: this.userId},
{fields: toFieldSelector(Accounts._autopublishFields.loggedInUser)});
} else {
return null;
}
}, /*suppress autopublish warning*/{is_auto: true});
// XXX this publish is neither dedup-able nor is it optimized by our
// special treatment of queries on a specific _id. Therefore this
// will have O(n^2) run-time performance every time a user document
// is changed (eg someone logging in). If this is a problem, we can
// instead write a manual publish function which filters out fields
// based on 'this.userId'.
Meteor.default_server.publish(null, function () {
var selector;
if (this.userId)
selector = {_id: {$ne: this.userId}};
else
selector = {};
return Meteor.users.find(
selector,
{fields: toFieldSelector(Accounts._autopublishFields.otherUsers)});
}, /*suppress autopublish warning*/{is_auto: true});
});
~~~~~
--
You received this message because you are subscribed to the Google Groups "meteor-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-talk...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
--
You received this message because you are subscribed to a topic in the Google Groups "meteor-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/meteor-talk/QKXe7qfBfqg/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to meteor-talk...@googlegroups.com.