kellyselden/ember-awesome-macros

Array macros findBy and filterBy not working with raw key reference

Opened this issue · 4 comments

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

I think something regressed in Ember.

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?

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

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