When is the isExpanded property initialized in the Controllers Guide Example?


#1

https://guides.emberjs.com/v2.12.0/controllers/


#2

I think it would be initialized on the first invocation of the action. Before that it would of course be “undefined” which is of course falsey. To initialize it to a default value, or to be a little more explicit about the props you’re using you could do something like:

import Ember from 'ember';

export default Ember.Controller.extend({
  isExpanded: false,
  actions: {
    toggleBody() {
      this.toggleProperty('isExpanded');
    }
  }
});

#3

Just like they did in the tutorial with a simple component:

import Ember from 'ember';
export default Ember.Component.extend({
  isWide: false
});

I didn’t understanded why they were concerned about initialization in one place (explaining components), and not in the another (explaining controllers). I was thinking there were something special about controllers… but maybe is just an unimportant detail in any case.

I preffer explicitness whenever possible, so I would do as you mention.


#4

https://github.com/emberjs/guides/pull/1979/files