News for hackers. Stuff that matters.
Re:Ember.js 2.7 and 2.8 beta released by akst on Wednesday July 27, 2016 @12:01AM (#12170450)
While I believe it would be nice to have a lambda version of this as it's a more general abstraction (and I believe there's something along those lines in ember), Ember makes a big emphasis on convention over configuration and this isn't limited to the build system but also it's runtime apis as well.

It's pretty common in ember to look up a property by string to set or get using the methods `get` and `set` on an ember object (ember has it's own object model[1]), and these property keys/strings can also express nested properties by spacing dots between nested property names. Like `user.get('organisation.name')` to get an user's organisation and the name of the organisation, this handles the situation when organisation is null, by returning null. So it's similar to `user.organisation?.name` in swift.

So for consistency sake and predictability sake ember also uses a string for this method. If we look at the implementation[2] you can see it use's a method called `guidFor`, it basically handles the whole null checking stuff, which in a lambda version would look something like

    var arr = [{ value: 'a' }, { value: 'a' }, { value: 'b' }, { value: 'b' }];
    arr.uniqBy(element => (element != null) ? element.value : null);
`guidFor`[3] also works for nested properties as well, so if you were looking for a property on `value` it would starts to get messy.

[1]: https://guides.emberjs.com/v2.1.0/object-model/

[2]: https://github.com/emberjs/ember.js/blob/45c92fb2c8931b4ca41...

[3]: https://github.com/emberjs/ember.js/blob/45c92fb2c8931b4ca41...

There are no comments on this comment yet.