@sukima wrote:
I’ve often not understood the following two coding styles and I am asking for some constructive feedback on them.
readOnly ALL THE THINGS!
I’ve seen this used everywhere. Anytime a computed property is used the
readOnly()
is added. I curious why it isn’t the default if it is important to always have it there.foo: computed('bar', { get() { ... } }).readOnly(),
I’ve asked and the only answers I’ve gotten is that the instructors at several Ember Bootcamps really push this style.
Destructuring hoop-da-loops
const { foo, bar, baz } = this.getProperties( 'foo', 'bar', 'baz' );
Versus
let foo = this.get('foo'); let bar = this.get('bar'); let baz = this.get('baz');
This is used for small and large sets of variables. I don’t understand the
const
either but the first one happens a lot in our code while the latter seems to read better and provides flexibility such as offering defaults or NullObjects:let foo = this.get('foo') || 'FOO'; let bar = this.get('bar') || {}; let baz = this.get('baz') || new NullObject();
I’m curious where these styles originate from and what others have to say about them.
Posts: 2
Participants: 2