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 #19645

Merged
merged 2 commits into from Jul 18, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@ember/-internals/utils/index.ts
Expand Up @@ -23,7 +23,7 @@ export {
} from './lib/super';
export { default as inspect } from './lib/inspect';
export { default as lookupDescriptor } from './lib/lookup-descriptor';
export { canInvoke, tryInvoke } from './lib/invoke';
export { canInvoke } from './lib/invoke';
export { default as makeArray } from './lib/make-array';
export { getName, setName } from './lib/name';
export { default as toString } from './lib/to-string';
Expand Down
51 changes: 0 additions & 51 deletions packages/@ember/-internals/utils/lib/invoke.ts
@@ -1,5 +1,3 @@
import { deprecate } from '@ember/debug';

/**
Checks to see if the `methodName` exists on the `obj`.

Expand All @@ -25,52 +23,3 @@ export function canInvoke(obj: any | null | undefined, methodName: string): obj
/**
@module @ember/utils
*/

/**
Checks to see if the `methodName` exists on the `obj`,
and if it does, invokes it with the arguments passed.

```javascript
import { tryInvoke } from '@ember/utils';

let d = new Date('03/15/2013');

tryInvoke(d, 'getTime'); // 1363320000000
tryInvoke(d, 'setFullYear', [2014]); // 1394856000000
tryInvoke(d, 'noSuchMethod', [2014]); // undefined
```

@method tryInvoke
@for @ember/utils
@static
@param {Object} obj The object to check for the method
@param {String} methodName The method name to check for
@param {Array} [args] The arguments to pass to the method
@return {*} the return value of the invoked method or undefined if it cannot be invoked
@public
@deprecated Use Javascript's optional chaining instead.
*/
export function tryInvoke(
obj: any | undefined | null,
methodName: string,
args: Array<any | undefined | null>
) {
deprecate(
`Use of tryInvoke is deprecated. Instead, consider using JavaScript's optional chaining.`,
false,
{
id: 'ember-utils.try-invoke',
until: '4.0.0',
for: 'ember-source',
since: {
enabled: '3.24.0',
},
url: 'https://deprecations.emberjs.com/v3.x#toc_ember-utils-try-invoke',
}
);

if (canInvoke(obj, methodName)) {
let method = obj[methodName];
return method.apply(obj, args);
}
}
60 changes: 0 additions & 60 deletions packages/@ember/-internals/utils/tests/try_invoke_test.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/@ember/utils/index.js
@@ -1,3 +1,2 @@
export { isNone, isBlank, isEmpty, isPresent } from '@ember/-internals/metal';
export { tryInvoke } from '@ember/-internals/utils';
export { compare, isEqual, typeOf } from '@ember/-internals/runtime';
1 change: 0 additions & 1 deletion packages/ember/index.js
Expand Up @@ -220,7 +220,6 @@ Ember.guidFor = utils.guidFor;
Ember.inspect = utils.inspect;
Ember.makeArray = utils.makeArray;
Ember.canInvoke = utils.canInvoke;
Ember.tryInvoke = utils.tryInvoke;
Ember.wrap = utils.wrap;
Ember.uuid = utils.uuid;

Expand Down
1 change: 0 additions & 1 deletion packages/ember/tests/reexports_test.js
Expand Up @@ -468,7 +468,6 @@ let allExports = [
['isEqual', '@ember/utils', 'isEqual'],
['isNone', '@ember/utils', 'isNone'],
['isPresent', '@ember/utils', 'isPresent'],
['tryInvoke', '@ember/utils', 'tryInvoke'],
['typeOf', '@ember/utils', 'typeOf'],

// @ember/version
Expand Down
1 change: 0 additions & 1 deletion tests/docs/expected.js
Expand Up @@ -573,7 +573,6 @@ module.exports = {
'trigger',
'triggerAction',
'triggerEvent',
'tryInvoke',
'trySet',
'type',
'typeInjection',
Expand Down