Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composing doesn't work with certain key names #453

Open
tcjr opened this issue Apr 10, 2018 · 2 comments
Open

Composing doesn't work with certain key names #453

tcjr opened this issue Apr 10, 2018 · 2 comments

Comments

@tcjr
Copy link

tcjr commented Apr 10, 2018

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')
@mriska
Copy link
Contributor

mriska commented May 13, 2018

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?

@kellyselden
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants