ASHdevelopment / standards

ASH Development Standards
28 stars 13 forks source link

Use brace expansion in computed properties #116

Closed ASH-Michael closed 6 years ago

ASH-Michael commented 6 years ago

To reduce redundancy and reduce amount of code written.

//bad
fullName: computed('user.firstName', 'user.lastName', function () {
  const firstName = get(this, 'user.firstName');
  const lastName = get(this, 'user.lastName');

  return firstName + ' ' + lastName;
})

//good
fullName: computed('user.{firstName,lastName}', function () {
  const { firstName, lastName } = get(this, 'user');

  return `${firstName} ${lastName}`;
})