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

Remove tryInvoke (from @ember/utils) calls #398

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 2 additions & 3 deletions addon/helpers/invoke.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { isArray as isEmberArray } from '@ember/array';
import { helper } from '@ember/component/helper';
import { tryInvoke } from '@ember/utils';
import RSVP from 'rsvp';

const { all } = RSVP;
Expand All @@ -10,14 +9,14 @@ export function invoke([methodName, ...args]) {

if (isEmberArray(obj)) {
return function() {
let promises = obj.map((item) => tryInvoke(item, methodName, args));
let promises = obj.map((item) => item[methodName]?.(...args));

return all(promises);
};
}

return function() {
return tryInvoke(obj, methodName, args);
return obj[methodName]?.(...args);
};
}

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/helpers/invoke-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ module('Unit | Helper | invoke', function() {
assert.equal(action(), 'calling mom in 1,2,3', 'it calls functions');
});

test('it cares about method arguments', function(assert) {
let object = {
callContact(name, number) {
return `calling ${name} with ${number}`;
}
};
let action = invoke(['callContact', 'mom', '1234567', object]);

assert.equal(action(), 'calling mom with 1234567', 'it cares about function args');
});

test('it is promise aware', function(assert) {
let done = assert.async();
let object = {
Expand Down