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

Error when composing collect, mapBy and sum #378

Open
gabrielgrant opened this issue Aug 22, 2017 · 1 comment
Open

Error when composing collect, mapBy and sum #378

gabrielgrant opened this issue Aug 22, 2017 · 1 comment

Comments

@gabrielgrant
Copy link
Contributor

gabrielgrant commented Aug 22, 2017

I have three props (downloadTime, processTime, uploadTime) each of which have an asMilliseconds prop. I want to sum those.

doing

{
  ...
  totalTimeMS: sum(array.mapBy(collect('downloadTime', 'processTime', 'uploadTime'), 'asMilliseconds')),
  ...
}

fails:

ember.debug.js:29026 Error while processing route: <route-name> (0 , _emberMacroHelpersCollapseKeys.collapseKeysWithMap) is not a function TypeError: (0 , _emberMacroHelpersCollapseKeys.collapseKeysWithMap) is not a function
    at Object.<anonymous> (http://localhost:4200/assets/vendor.js:180009:89)
    at Module.callback (http://localhost:4200/assets/pachdash.js:3248:73)
    at Module.exports (http://localhost:4200/assets/vendor.js:119:32)
    at requireModule (http://localhost:4200/assets/vendor.js:34:18)
    at Class._extractDefaultExport (http://localhost:4200/assets/vendor.js:182548:20)
    at Class.resolveOther (http://localhost:4200/assets/vendor.js:182245:32)
    at Class.superWrapper [as resolveOther] (http://localhost:4200/assets/vendor.js:56585:22)
    at Class.resolve (http://localhost:4200/assets/vendor.js:21030:35)
    at resolve (http://localhost:4200/assets/vendor.js:18426:36)
    at Registry.resolve (http://localhost:4200/assets/vendor.js:17885:21)
ember.debug.js:18015 TypeError: (0 , _emberMacroHelpersCollapseKeys.collapseKeysWithMap) is not a function
    at Object.<anonymous> (create-class-computed.js:60)
    at Module.callback (datum-stats.js:7)
    at Module.exports (loader.js:114)
    at requireModule (loader.js:29)
    at Class._extractDefaultExport (resolver.js:382)
    at Class.resolveOther (resolver.js:79)
    at Class.superWrapper [as resolveOther] (ember.debug.js:40879)
    at Class.resolve (ember.debug.js:5324)
    at resolve (ember.debug.js:2720)
    at Registry.resolve (ember.debug.js:2179)

However what seems to be the pure Ember/JS equivalent works fine:

{
  ...
  _durations: Ember.computed.collect('downloadTime', 'processTime', 'uploadTime'),
  totalTime: Ember.computed('_durations.[]', function() {
    let durationsMS = this.get('_durations').mapBy('asMilliseconds');
    let totalTimeMS = durationsMS.reduce((a, b) => a+b, 0);
    return Duration.create({value: totalTimeMS});
  }),
  ...
}
@kellyselden
Copy link
Owner

kellyselden commented Aug 22, 2017

Thanks for the issue. If you could submit a failing test, that would greatly speed up the fixing process.

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

2 participants