Closed anthonyboutinov closed 8 years ago
@anthonyboutinov you'll want to avoid using the ES6 arrow function syntax here as this
will be bound to outer function scope. In other words:
Meteor.publish('events', (categoryIds, options) => {
Should be:
Meteor.publish('events', function(categoryIds, options) {
I think it would help to add the remark of not using ES6 to the README
@sladkovm it wouldn't really make sense to as it's Meteor's publish API that puts methods on the function context.
This issue is related to #84. I maintain the same stance as @dburles.
With any javascript project, one must always consider the consequence concerning the function context this
when using ES6 arrow functions.
In general, the ES6 arrow function is not intended as a blind replacement for traditional ES5 function definitions, especially where callbacks are concerned, and furthermore when your callback utilizes this
within the callback.
Meteor even documents [1] that Meteor.publish
uses the callback's context.
Function called on the server each time a client subscribes. Inside the function,
this
is the publish handler object, described below. If the client passed arguments tosubscribe
, the function is called with the same arguments.
While I don't relish the idea of enumerating broad programming mistakes in the README, it may be worthwhile to use the FAQ label and apply it to these issues. At the very least, we can add a FAQ link to the README. The README remains idempotent to changing trends in programming mistakes, and users are presented with more direction to find these discussions. Thoughts, @dburles?
@boxofrox since Meteor is a platform that caters to all skill levels we might as well if it saves people a bit of a headache, the arrow function can be a bit of a gotcha for new developers (and those new to ES6).
I've added the a url for frequently asked questions to the README.
I'm trying to publish
events.count
:I get an exception:
METEOR@1.4.1.2 tmeasday:publish-counts@0.8.0