From 9380ac10a5674c6b5b812e4a6ad550b06dc2d499 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Tue, 16 Feb 2021 00:54:28 -0300 Subject: [PATCH 1/2] Remove tryInvoke (from @ember/utils) calls https://emberjs.github.io/rfcs/0673-deprecate-tryinvoke.html --- addon/helpers/invoke.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addon/helpers/invoke.js b/addon/helpers/invoke.js index a78a4ca0..b34a4ef4 100644 --- a/addon/helpers/invoke.js +++ b/addon/helpers/invoke.js @@ -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; @@ -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); }; } From 4a91eb1d62bbba82a46e62c6b6949fd718f22017 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Sun, 28 Feb 2021 20:34:46 -0300 Subject: [PATCH 2/2] Add spread operator in invoke helper to keep behaviour As pointed by CR: @bertdeblock --- addon/helpers/invoke.js | 4 ++-- tests/unit/helpers/invoke-test.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/addon/helpers/invoke.js b/addon/helpers/invoke.js index b34a4ef4..d05c9ce0 100644 --- a/addon/helpers/invoke.js +++ b/addon/helpers/invoke.js @@ -9,14 +9,14 @@ export function invoke([methodName, ...args]) { if (isEmberArray(obj)) { return function() { - let promises = obj.map((item) => item[methodName]?.(args)); + let promises = obj.map((item) => item[methodName]?.(...args)); return all(promises); }; } return function() { - return obj[methodName]?.(args); + return obj[methodName]?.(...args); }; } diff --git a/tests/unit/helpers/invoke-test.js b/tests/unit/helpers/invoke-test.js index 7647d250..5cc934fb 100644 --- a/tests/unit/helpers/invoke-test.js +++ b/tests/unit/helpers/invoke-test.js @@ -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 = {