dburles / meteor-collection-helpers

⚙️ Meteor package that allows you to define helpers on your collections
https://atmospherejs.com/dburles/collection-helpers
MIT License
498 stars 31 forks source link

Ecmascript problem #78

Open mervynteo opened 7 years ago

mervynteo commented 7 years ago

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?

dburles commented 7 years ago

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?

mervynteo commented 7 years ago

@dburles updated as above. Thanks!

dburles commented 7 years ago

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