Skip to content

Commit

Permalink
Remove sendAction and string action passing
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Jul 18, 2021
1 parent 9149433 commit 7148019
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 965 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { tracked } from '@ember/-internals/metal';
import { TargetActionSupport } from '@ember/-internals/runtime';
import { TextSupport } from '@ember/-internals/views';
import { EMBER_MODERNIZED_BUILT_IN_COMPONENTS } from '@ember/canary-features';
import { assert, deprecate } from '@ember/debug';
import { JQUERY_INTEGRATION, SEND_ACTION } from '@ember/deprecated-features';
import { assert } from '@ember/debug';
import { JQUERY_INTEGRATION } from '@ember/deprecated-features';
import { action } from '@ember/object';
import { isConstRef, isUpdatableRef, Reference, updateRef, valueForRef } from '@glimmer/reference';
import Component from '../component';
Expand Down Expand Up @@ -209,86 +209,6 @@ export function handleDeprecatedFeatures(
target: InternalComponentConstructor<AbstractInput>,
attributeBindings: Array<string | [attribute: string, argument: string]>
): void {
if (SEND_ACTION) {
let angle = target.toString();
let { prototype } = target;

interface View {
send(action: string, ...args: unknown[]): void;
}

let isView = (target: {}): target is View => {
return typeof (target as Partial<View>).send === 'function';
};

let superListenerFor = prototype['listenerFor'];

Object.defineProperty(prototype, 'listenerFor', {
configurable: true,
enumerable: false,
value: function listenerFor(this: AbstractInput, name: string): EventListener {
const actionName = this.named(name);

if (typeof actionName === 'string') {
deprecate(
`Passing actions to components as strings (like \`<${angle} @${name}="${actionName}" />\`) is deprecated. ` +
`Please use closure actions instead (\`<${angle} @${name}={{action "${actionName}"}} />\`).`,
false,
{
id: 'ember-component.send-action',
for: 'ember-source',
since: {},
until: '4.0.0',
url: 'https://deprecations.emberjs.com/v3.x#toc_ember-component-send-action',
}
);

const { caller } = this;

assert('[BUG] missing caller', caller && typeof caller === 'object');

let listener: Function;

if (isView(caller)) {
listener = (...args: unknown[]) => caller.send(actionName, ...args);
} else {
assert(
`The action '${actionName}' did not exist on ${caller}`,
typeof caller[actionName] === 'function'
);

listener = caller[actionName];
}

let deprecatedListener = (...args: unknown[]) => {
deprecate(
`Passing actions to components as strings (like \`<${angle} @${name}="${actionName}" />\`) is deprecated. ` +
`Please use closure actions instead (\`<${angle} @${name}={{action "${actionName}"}} />\`).`,
false,
{
id: 'ember-component.send-action',
for: 'ember-source',
since: {},
until: '4.0.0',
url: 'https://deprecations.emberjs.com/v3.x#toc_ember-component-send-action',
}
);

return listener(...args);
};

if (this.isVirtualEventListener(name, deprecatedListener)) {
return devirtualize(deprecatedListener);
} else {
return deprecatedListener as EventListener;
}
} else {
return superListenerFor.call(this, name);
}
},
});
}

if (EMBER_MODERNIZED_BUILT_IN_COMPONENTS) {
let { prototype } = target;

Expand Down
10 changes: 5 additions & 5 deletions packages/@ember/-internals/glimmer/lib/helpers/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ export const ACTIONS = new _WeakSet();
Closure actions curry both their scope and any arguments. When invoked, any
additional arguments are added to the already curried list.
Actions should be invoked using the [sendAction](/ember/release/classes/Component/methods/sendAction?anchor=sendAction)
method. The first argument to `sendAction` is the action to be called, and
additional arguments are passed to the action function. This has interesting
properties combined with currying of arguments. For example:
Actions are presented in JavaScript as callbacks, and are
invoked like any other JavaScript function.
For example
```app/components/update-name.js
import Component from '@glimmer/component';
Expand Down Expand Up @@ -152,7 +152,7 @@ export const ACTIONS = new _WeakSet();
export default Component.extend({
click() {
// Note that model is not passed, it was curried in the template
this.sendAction('submit', 'bob');
this.submit('bob');
}
});
```
Expand Down
Loading

0 comments on commit 7148019

Please sign in to comment.