Dereferencing/Destructuring Ember Global... Best Practice?


#1

In regards to preparing for a world without the Ember global, which would be considered “the right way” to do this?

import Ember from 'ember';
const { computed } = Ember;
const { alias, reads } = Computed

export default Ember.Component.extend({
  prop1: alias('some.thing'),
  prop2: reads('other.thing'),
  prop3: computed('coolbeans', function() { ... 

Or

import Ember from 'ember';
const { computed } = Ember;

export default Ember.Component.extend({
  prop1: computed.alias('some.thing'),
  prop2: computed.reads('other.thing'),
  prop3: computed('coolbeans', function() { ... 

(The difference is using computed.alias, computed.reads vs destructuring all the way down to alias and reads).

Thanks! Adam


#2

I don’t think its a big deal either way… but my preference is for the first method.


#3
import Ember from 'ember';
const { computed: { alias, reads } } = Ember;

or

import { alias, reads }  from 'ember-computed';

I believe the latter might be being recommended against at the moment, as ember’s module interface is not finalised yet, but it won’t exactly be complex to upgrade from


#4

Awesome - thanks guys.


#5

This is what’s coming https://github.com/emberjs/rfcs/blob/master/text/0176-javascript-module-api.md