ember-awesome-macros icon indicating copy to clipboard operation
ember-awesome-macros copied to clipboard

Array macros findBy and filterBy not working with raw key reference

Open dagroe opened this issue 5 years ago • 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

dagroe avatar Feb 10 '20 07:02 dagroe

I think something regressed in Ember.

kellyselden avatar Feb 10 '20 10:02 kellyselden

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 avatar May 19 '20 09:05 ctjhoa

I found an issue in ember-macro-helper which is the root cause I think https://github.com/kellyselden/ember-macro-helpers/issues/291

ctjhoa avatar May 19 '20 09:05 ctjhoa

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

RobbieTheWagner avatar Jun 08 '20 14:06 RobbieTheWagner