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

Array macros findBy and filterBy not working with raw key reference #598

Open
dagroe opened this issue Feb 10, 2020 · 4 comments
Open

Array macros findBy and filterBy not working with raw key reference #598

dagroe opened this issue Feb 10, 2020 · 4 comments

Comments

@dagroe
Copy link

dagroe commented Feb 10, 2020

In a fresh ember 3.15 install the array macros filterBy and findBy are not working as expected when using raw() to provide the key reference.

I created a repository that illustrates the issue here: https://github.com/DanielGroeger/issue-eam-raw

Passing a reference to a field that contains the key works fine while using raw does not work. E.g.:

export default class Company {

  attributeToFilterBy = 'age';
  attributeToFindBy = 'firstname';

  employees = [
    new Person("Mike", "Smith", 21),
    new Person("Marie", "Claire", 50),
    new Person("Albert", "Einstein", 47),
    new Person("Edgar", "Miller", 33),
    new Person("Simon", "Baker", 50)
  ];


  @filterBy('employees', 'attributeToFilterBy', 50)
  filteredEmployees;

  @filterBy('employees', raw('age'), 50)
  filteredEmployeesRaw;

  @findBy('employees', 'attributeToFindBy', raw('Marie'))
  foundEmployee;

  @findBy('employees', raw('firstname'), raw('Marie'))
  foundEmployeeRaw;
}

filteredEmployees correctly contains two Person objects, filteredEmployeesRaw contains the entire target array. foundEmployee correctly contains a single Person object, foundEmployeeRaw the entire target array.

I have tried different setups, using native classes or ember object. Originally the error occurred when upgrading a project using typescript from ember 3.12.0 to 3.15.0

@kellyselden
Copy link
Owner

I think something regressed in Ember.

@ctjhoa
Copy link
Contributor

ctjhoa commented May 19, 2020

Ok so I have the same issue on my app and it's mandatory for us.
I narrowed down the issue to the optional feature default-async-observers which is enabled by default in 3.15.0.

So the workaround is to disable this feature.

@kellyselden The only observer I found is this one in ember-macro-helper:
https://github.com/kellyselden/ember-macro-helpers/blob/master/addon/create-class-computed.js#L54
Does it ring any bell?

@ctjhoa
Copy link
Contributor

ctjhoa commented May 19, 2020

I found an issue in ember-macro-helper which is the root cause I think
kellyselden/ember-macro-helpers#291

@RobbieTheWagner
Copy link

I'm hitting this issue with mapBy as well. Any updates here?

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

4 participants