Closed leprekon91 closed 4 years ago
Actually, even better solution would be:
Meteor.publish(null, function() {
if (this.userId) {
return Meteor.roleAssignment.find({ 'user._id': this.userId });
}
return this.ready();
});
Thanks for pointing out the missing semicolon.
Please elaborate why the second of your code snippets would be a better solution. To me, this is an opinionated choice of which I like the first (not necessarily for not using the return
, but specially for leaving the else
in place).
I personally see nothing wrong here.. The current code is clean and intention is clear. It's not necessary to return this.ready()
from a publication, only to call the function.
I had no idea that you can invoke the ready callback and get the same result on the publication. I thought that the function is actually invoked on the client after the ready signal is received from the server, as a way to tell the client it is done sending the current batch of docs.
Well, the function Meteor.publish()
is only available on the server - not on the client (https://docs.meteor.com/api/pubsub.html#Meteor-publish). The client only subscribes to a publication using Meteor.subscribe()
(https://docs.meteor.com/api/pubsub.html#Meteor-subscribe).
I understand that. I just thought that instead of an array of cursors the publication will return a callback function when ready (this.ready()
), then the client calls this function.
Anyway, I thought that this would be a nicer change because I have a prettier plugin that just won't shut up about this. And I never knew that you can just call this.ready(), and get the same results. Thought maybe I'll share my pain. :-)
Thanks for the feedback though 👍 I really appreciate that you took the time 😃
I have a prettier plugin that just won't shut up about this.
@leprekon91 This sounds like the consistent-returns
rule for eslint. Personally, I find it to be completely useless and annoying and therefore disable it.
Yeah, but I prefer it that way actually... Feels cleaner and keeps my boss happy during code reviews...
Shouldn't the publication in the README file under "Changes between 2.x and 3.0" and "Installing",
return this.ready()
and not call it?