Skip to content
Closed
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
7 changes: 7 additions & 0 deletions packages/@ember/-internals/deprecations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ export const DEPRECATIONS = {
until: '7.5.0',
url: 'https://deprecations.emberjs.com/id/deprecate-comparable-mixin',
}),
DEPRECATE_TARGET_ACTION_SUPPORT: deprecation({
for: 'ember-source',
id: 'deprecate-target-action-support',
since: { available: '7.3.0' },
until: '8.0.0',
url: 'https://deprecations.emberjs.com/id/deprecate-target-action-support',
}),
};

export function deprecateUntil(message: string, deprecation: DeprecationObject) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import { moduleFor, RenderingTestCase, runTask } from 'internal-test-helpers';
import {
expectDeprecation,
moduleFor,
RenderingTestCase,
runTask,
testUnless,
} from 'internal-test-helpers';

import { action, set } from '@ember/object';
import Mixin from '@ember/object/mixin';
import Controller from '@ember/controller';
import EmberObject from '@ember/object';
import { DEPRECATIONS } from '@ember/-internals/deprecations';

import { Component } from '../../utils/helpers';

moduleFor(
'Components test: send',
class extends RenderingTestCase {
['@test sending to undefined actions triggers an error'](assert) {
assert.expect(2);
[`${testUnless(
DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isRemoved
)} @test sending to undefined actions triggers an error`](assert) {
assert.expect(3);

expectDeprecation(
/Calling `\.send\(\)` on/,
DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled
);

let component;

Expand Down Expand Up @@ -39,7 +53,14 @@ moduleFor(
}, /had no action handler for: baz/);
}

['@test `send` will call send from a target if it is defined']() {
[`${testUnless(
DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isRemoved
)} @test \`send\` will call send from a target if it is defined`]() {
expectDeprecation(
/Calling `\.send\(\)` on/,
DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled
);

let component;
let target = {
send: (message, payload) => {
Expand All @@ -64,8 +85,15 @@ moduleFor(
runTask(() => component.send('foo', 'baz'));
}

['@test a handled action can be bubbled to the target for continued processing']() {
this.assert.expect(2);
[`${testUnless(
DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isRemoved
)} @test a handled action can be bubbled to the target for continued processing`]() {
this.assert.expect(3);

expectDeprecation(
/Calling `\.send\(\)` on/,
DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled
);

let component;

Expand Down Expand Up @@ -97,8 +125,15 @@ moduleFor(
runTask(() => component.send('poke'));
}

["@test action can be handled by a superclass' actions object"](assert) {
this.assert.expect(4);
[`${testUnless(
DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isRemoved
)} @test action can be handled by a superclass' actions object`](assert) {
this.assert.expect(5);

expectDeprecation(
/Calling `\.send\(\)` on/,
DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled
);

let component;

Expand Down Expand Up @@ -166,7 +201,14 @@ moduleFor(
});
}

['@test asserts if called on a destroyed component']() {
[`${testUnless(
DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isRemoved
)} @test asserts if called on a destroyed component`]() {
expectDeprecation(
/Calling `\.send\(\)` on/,
DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled
);

let component;

this.owner.register(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Mixin from '@ember/object/mixin';
import { get } from '@ember/-internals/metal/lib/property_get';
import { assert } from '@ember/debug';
import { deprecateUntil, DEPRECATIONS } from '@ember/-internals/deprecations';

/**
`ActionHandler` is available on some familiar classes including
Expand Down Expand Up @@ -164,6 +165,7 @@ const ActionHandler = Mixin.create({
```

@property actions
@deprecated Use the `@action` decorator instead.
@type Object
@default null
@public
Expand Down Expand Up @@ -197,11 +199,16 @@ const ActionHandler = Mixin.create({
```

@method send
@deprecated Use direct method calls instead.
@param {String} actionName The action to trigger
@param {*} context a context to send with the action
@public
*/
send(actionName: string, ...args: any[]) {
deprecateUntil(
`Calling \`.send()\` on ${this} is deprecated. Invoke the corresponding method directly instead.`,
DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT
);
assert(
`Attempted to call .send() with the action '${actionName}' on the destroyed object '${this}'.`,
!this.isDestroying && !this.isDestroyed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { get } from '@ember/-internals/metal/lib/property_get';
import computed from '@ember/-internals/metal/lib/computed';
import Mixin from '@ember/object/mixin';
import { assert } from '@ember/debug';
import { deprecateUntil, DEPRECATIONS } from '@ember/-internals/deprecations';
import { DEBUG } from '@glimmer/env';

/**
Expand Down Expand Up @@ -104,11 +105,17 @@ const TargetActionSupport = Mixin.create({
```

@method triggerAction
@deprecated Use a direct method call or closure action instead.
@param opts {Object} (optional, with the optional keys action, target and/or actionContext)
@return {Boolean} true if the action was sent successfully and did not return false
@private
*/
triggerAction(opts: { action?: string; target?: unknown; actionContext?: unknown } = {}) {
deprecateUntil(
`Calling \`triggerAction\` on ${this} is deprecated. Invoke the target method directly instead.`,
DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT
);

let { action, target, actionContext } = opts;
action = action || get(this, 'action');
target = target || getTarget(this);
Expand Down
Loading
Loading