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

implement sum helper as strict alias for add helper #614

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions addon/helpers/sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { helper } from '@ember/component/helper';
import { add } from './add';

/**
* Alias for {{add}} helper
*
* ```hbs
* {{sum a b}}
* ```
*
* @param {number[]} numbers A list of numbers to sum
* @return {number} The sum of all the passed numbers
*/
export function sum(numbers) {
return add(numbers);
}

export default helper(sum);
1 change: 1 addition & 0 deletions app/helpers/sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, sum } from 'ember-math-helpers/helpers/sum';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mifrill I think we could just export from add here and be good to go. Something like this maybe?

Suggested change
export { default, sum } from 'ember-math-helpers/helpers/sum';
export { default, add as sum } from 'ember-math-helpers/helpers/add';

Copy link
Contributor Author

@Mifrill Mifrill Sep 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwwagner90 well, in this way file addon/helpers/sum.js will came redundant, right? So, then we would need to customize documentation somehow that provided by ember-cli-addon-docs because comments in file addon/helpers/sum.js have auto-converts into the component with documentation.
However, the original proposal is to have the documented sum helper:
Selection_823
maybe it's better to keep it consistent with the documentation addon with no this requested change, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwwagner90 could you give an advice on how to customize documentation for this particular case?

15 changes: 15 additions & 0 deletions tests/unit/helpers/sum-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { sum } from 'dummy/helpers/sum';
import { add } from 'dummy/helpers/add';
import { module, test } from 'qunit';

module('Unit | Helper | sum', function () {
test('works as alias to add', function (assert) {
const input = [20, 10];
assert.strictEqual(sum(input), add(input));
});

test('works as alias to add for multiple arguments', function (assert) {
const input = [1, 2, 3, 4, 5];
assert.strictEqual(sum(input), add(input));
});
});