mardi 17 octobre 2017

Is there a shorter way to write Ember computed/get method?

Is there a short way to write the code below (from Rock & Roll with Ember.js book):

export default Ember.Controller.extend({
  noSongs: Ember.computed('model.songs.length', function() {
    return this.get('model.songs.length') === 0;
  }),
  (...)
});

I reckon I can desctructure import for Controller, get and computed:

import { Controller, get, computed } from 'ember';

Questions

  • Can I use arrow function inside the computed instead of function?
  • Is there a more javascript-ish way to do this.get('model.songs.length') as it feels awkward to have length as a string?



Aucun commentaire:

Enregistrer un commentaire