Skip to content

Commit

Permalink
Unify deprecation ids and prepare for svelte
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Camba committed Jun 14, 2018
1 parent 65f390b commit 53d8e36
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 46 deletions.
1 change: 1 addition & 0 deletions packages/@ember/deprecated-features/index.ts
@@ -1,3 +1,4 @@
export const SEND_ACTION = !!'3.4.0';
export const PROPERTY_BASED_DESCRIPTORS = !!'3.2.0';
export const EMBER_EXTEND_PROTOTYPES = !!'3.2.0-beta.5';
export const DEPRECATE_OPTIONS_MISSING = !!'2.1.0-beta.1';
Expand Down
98 changes: 53 additions & 45 deletions packages/ember-views/lib/mixins/action_support.js
Expand Up @@ -5,28 +5,38 @@ import { inspect } from 'ember-utils';
import { Mixin, get } from 'ember-metal';
import { assert, deprecate } from '@ember/debug';
import { MUTABLE_CELL } from '../compat/attrs';
import { SEND_ACTION } from '@ember/deprecated-features';

function validateAction(component, actionName) {
if (actionName && actionName[MUTABLE_CELL]) {
actionName = actionName.value;
}

assert(
`The default action was triggered on the component ${component.toString()}, but the action name (${actionName}) was not a string.`,
actionName === null ||
actionName === undefined ||
typeof actionName === 'string' ||
typeof actionName === 'function'
);
return actionName;
}
const mixinObj = {
send(actionName, ...args) {
assert(
`Attempted to call .send() with the action '${actionName}' on the destroyed object '${this}'.`,
!this.isDestroying && !this.isDestroyed
);

/**
@class ActionSupport
@namespace Ember
@private
*/
export default Mixin.create({
let action = this.actions && this.actions[actionName];

if (action) {
let shouldBubble = action.apply(this, args) === true;
if (!shouldBubble) {
return;
}
}

let target = get(this, 'target');
if (target) {
assert(
`The \`target\` for ${this} (${target}) does not have a \`send\` method`,
typeof target.send === 'function'
);
target.send(...arguments);
} else {
assert(`${inspect(this)} had no action handler for: ${actionName}`, action);
}
},
};

if (SEND_ACTION) {
/**
Calls an action passed to a component.
Expand Down Expand Up @@ -110,8 +120,9 @@ export default Mixin.create({
@param [action] {String} the action to call
@param [params] {*} arguments for the action
@public
@deprecated
*/
sendAction(action, ...contexts) {
let sendAction = function sendAction(action, ...contexts) {
assert(
`Attempted to call .sendAction() with the action '${action}' on the destroyed object '${this}'.`,
!this.isDestroying && !this.isDestroyed
Expand Down Expand Up @@ -146,32 +157,29 @@ export default Mixin.create({
actionContext: contexts,
});
}
},
};

let validateAction = function validateAction(component, actionName) {
if (actionName && actionName[MUTABLE_CELL]) {
actionName = actionName.value;
}

send(actionName, ...args) {
assert(
`Attempted to call .send() with the action '${actionName}' on the destroyed object '${this}'.`,
!this.isDestroying && !this.isDestroyed
`The default action was triggered on the component ${component.toString()}, but the action name (${actionName}) was not a string.`,
actionName === null ||
actionName === undefined ||
typeof actionName === 'string' ||
typeof actionName === 'function'
);
return actionName;
};

let action = this.actions && this.actions[actionName];

if (action) {
let shouldBubble = action.apply(this, args) === true;
if (!shouldBubble) {
return;
}
}
mixinObj.sendAction = sendAction;
}

let target = get(this, 'target');
if (target) {
assert(
`The \`target\` for ${this} (${target}) does not have a \`send\` method`,
typeof target.send === 'function'
);
target.send(...arguments);
} else {
assert(`${inspect(this)} had no action handler for: ${actionName}`, action);
}
},
});
/**
@class ActionSupport
@namespace Ember
@private
*/
export default Mixin.create(mixinObj);
2 changes: 1 addition & 1 deletion packages/ember-views/lib/mixins/text_support.js
Expand Up @@ -312,7 +312,7 @@ function sendAction(eventName, view, event) {
deprecate(
`Passing actions to components as strings (like {{input ${eventName}="${actionName}"}}) is deprecated. Please use closure actions instead ({{input ${eventName}=(action "${actionName}")}})`,
false,
{ id: 'ember-input.send-action', until: '4.0.0' }
{ id: 'ember-component.send-action', until: '4.0.0' }
);
view.triggerAction({
action: actionName,
Expand Down

0 comments on commit 53d8e36

Please sign in to comment.