meteor-collection-helpers icon indicating copy to clipboard operation
meteor-collection-helpers copied to clipboard

Ecmascript problem

Open mervynteo opened this issue 8 years ago • 3 comments

I used a global helper below. However after I changed to ES6 or 2015 format, it broke.

Original

Channels.helpers({
   oppParty: function (){ 
      if( this.originator === Meteor.userId() ) {
         return Meteor.users.findOne({ _id: this.recipient });
      } else {
         return Meteor.users.findOne({ _id: this.originator });
      }
   }
});

changed to

Channels.helpers({
   oppParty (){ return this.originator === Meteor.userId() ? this.recipient : this.originator; }
});

I tried various combination and installed, uninstalled ES6, nothing worked. Anyone has the same issue?

mervynteo avatar May 04 '17 03:05 mervynteo

Using object method shorthand is okay however don't use arrow functions as then this won't be bound to the correct context. Could you post a more complete code example?

dburles avatar May 04 '17 03:05 dburles

@dburles updated as above. Thanks!

mervynteo avatar May 04 '17 03:05 mervynteo

Looks fine to me (see the examples in the readme).

dburles avatar May 04 '17 06:05 dburles