ember-script icon indicating copy to clipboard operation
ember-script copied to clipboard

concatenated properties work different then in "normal" ember coffeescript

Open hajee opened this issue 11 years ago • 4 comments

In 'normal' ember, when when the first property of a concatenated set of properties returns an 'undefined', the total get returns an 'undefined'.

@get('first.second')

When I use emberscript for this:

@first.second

it is compiled into:

return get$(get$(this, 'first'), 'second');

This raises an error

Cannot call get with 'second' on an undefined object.

hajee avatar Apr 07 '13 21:04 hajee

So I am slightly torn on this one. My personal preference is to use the ?. operator if you want soaked property access. What if instead the following:

@first?.second

Compiled into:

this.get('first.second')

Thoughts?

ghempton avatar Apr 07 '13 23:04 ghempton

How would that work on an extended concatenation like:

this.get('first.second.third')

hajee avatar Apr 08 '13 05:04 hajee

@first?.second?.third if you wanted all the access to be soaked.

ghempton avatar Apr 08 '13 16:04 ghempton

Have you considered always soaking unless you use the * operator? I haven't really looked into it, but ut seems Ember.set & Ember.get can handle this.

@first.second.third

would compile into:

get$(this, 'first.second.third')

and

@first*.second.third

would compile into:

this.first.get$(second, 'third')

and

@first*.second*.third

would compile into:

this.first.third

hajee avatar Apr 08 '13 19:04 hajee