emberjs / guides

This repository is DEPRECATED!
https://github.com/ember-learn/guides-source
Other
283 stars 874 forks source link

Off by 1 error in object-model/computed-properties-and-aggregate-data/ #2319

Closed jal90 closed 6 years ago

jal90 commented 6 years ago

The following block of code suggests that Ember starts indexing at 1, which isn't the case:

import EmberObject, { computed } from '@ember/object';

const Hamster = EmberObject.extend({
  excitingChores: computed('chores.[]', function() {
    return this.get('chores').map(function(chore, index) {
      return `CHORE ${index}: ${chore.toUpperCase()}!`;
    });
  })
});

const hamster = Hamster.create({
  chores: ['clean', 'write more unit tests']
});

hamster.get('excitingChores'); // ['CHORE 1: CLEAN!', 'CHORE 2: WRITE MORE UNIT TESTS!']
hamster.get('chores').pushObject('review code');
hamster.get('excitingChores'); // ['CHORE 1: CLEAN!', 'CHORE 2: WRITE MORE UNIT TESTS!', 'CHORE 3: REVIEW CODE!']

The string interpolation should have index+1, or hamster.get('excitingChores') should log CHORE 0: CLEAN!

yawboakye commented 6 years ago

@jal90 You got that spot on. It's also your opportunity to contribute to Ember :grinning: Do you want to follow it up with a PR?

jal90 commented 6 years ago

Absolutely! I'll try to get that in tomorrow.

On Sat, Apr 21, 2018 at 7:53 AM, Yaw Boakye notifications@github.com wrote:

@jal90 https://github.com/jal90 You got that spot on. It's also your opportunity to contribute to Ember 😀 Do you want to follow it up with a PR?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/emberjs/guides/issues/2319#issuecomment-383289345, or mute the thread https://github.com/notifications/unsubscribe-auth/AcNiDVZl-Rb_BnsBjxShhxS2OeTQg9dWks5tqx3PgaJpZM4TIrq8 .

jal90 commented 6 years ago

Submitted my pull request, awaiting review