Anyone have thoughts on best practices for initializing state and variables within a component?
Seems like didInsertElement is a convenient place for this kind of logic. But was wondering if there are any other patterns worth considering.
To be more concrete imagine a very simple component with some flags
App.MyComponent = Ember.Component.extend({
someFlag: null,
anotherFlag: null,
actions: {
updateSomeFlag: function(value) {
this.set('someFlag', value);
},
updateAnotherFlag: function(value) {
this.set('anotherFlag', value);
}
},
didInsertElement: function() {
// Initialize some state for this component
this.set('anotherFlag',"foo");
this.set('someFlag', "bar");
}
});
I suppose implicitly these parameters can be defined by the component in the template that declares it
{{ my-component someFlag="foo" anotherFlag="bar" }}
But wondering about the case where I want a much simpler interface surface area with more complex internal logic around setting up the default values of my component, that the external world shouldnāt have to think about.
{{ my-component }}
didInsertElement seems perfectly adequate, but wondering if other people are finding that they use a dedicated initialization method, or ever find they need to call super.