Composing doesn't work with certain key names
Opened this issue · 2 comments
I'm having a problem with how the dependent keys are calculated for certain (JSON) data. It turns out that you cannot use some composable macros with data which has a space in the keys. Consider this array:
selectedField: 'id',
data: [
{ fname: 'George', "last name": "Orwell", id:1 },
{ fname: 'Michelle', "last name": "Obama", id:2 },
{ fname: 'George', "last name": "Washington", id:3 },
{ fname: 'Martha', "last name": "Washington", id:4 }
],
uniques: array.uniqBy('data', 'selectedField')
If you set selectedField
to "id" or "fname", it computes the uniques
value as expected. But if you set it to "last name", a runtime error is raised:
Assertion Failed: Brace expanded properties cannot contain spaces, e.g. "user.{firstName, lastName}" should be "user.{firstName,lastName}"
Here's a Twiddle demonstrating this:
https://ember-twiddle.com/e453fcf9cb9964caa2df438b0751c7e9?openFiles=templates.application.hbs%2C
Also, fwiw, using a dependent property with a space is valid for the non-awesome stock macros. E.g.,
uniqueLastNames: Ember.computed.uniqBy('data', 'last name')
Hi @tcjr,
I think this is actually an error message that comes from Ember.js and not something that ember-awesome-macros can affect.
See this issue for discussion: emberjs/ember.js#16585
@kellyselden do you agree?
https://github.com/emberjs/ember.js/blob/v2.15.3/packages/ember-runtime/lib/computed/reduce_computed_macros.js#L432 Looks like Ember never watches the last name
property, so changes to the property don't recompute. Don't know what we can do about that. We can detect a space, and fall back to the broken way that Ember does it, but that doesn't seem right.