Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove arrow function usage in README #63

Open
rwjblue opened this issue Apr 5, 2017 · 2 comments
Open

Remove arrow function usage in README #63

rwjblue opened this issue Apr 5, 2017 · 2 comments

Comments

@rwjblue
Copy link

rwjblue commented Apr 5, 2017

The README shows the following example:

import Ember from 'ember';
import computed from 'ember-macro-helpers/computed';

export default Ember.Component.extend({
  key1: false,
  key2: true,

  result: computed(Ember.computed.or('key1', 'key2'), value => {
    console.log(value); // true
    // do something else
  })
});

But as you know, using an arrow function for result's callback will not allow access to the current object instance as this. In this case, you are not using this so the example is technically correct, but it seems to be tripping folks up a bit (saw some convo in slack about this).

@Turbo87
Copy link
Contributor

Turbo87 commented Apr 5, 2017

the example on slack was:

  computed1: computed('key1.[]', value => {
    this.get('aNumber');
  }),

but then again if you wanted to access aNumber from that function you should've declared it as a dependent key and then it would've been available as an argument to that function 😉

I'd agree though that this has potential to be misunderstood and it probably won't do any harm if a non-arrow function would be used in that example.

@lolmaus
Copy link
Contributor

lolmaus commented Jul 30, 2017

Using an arrow function ensures that the CP is pure. I think it's a very good practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants