From 53d8e369d01023bfc2fc444a02769919561a9847 Mon Sep 17 00:00:00 2001 From: Miguel Camba Date: Thu, 14 Jun 2018 13:11:37 +0200 Subject: [PATCH] Unify deprecation ids and prepare for svelte --- packages/@ember/deprecated-features/index.ts | 1 + .../ember-views/lib/mixins/action_support.js | 98 ++++++++++--------- .../ember-views/lib/mixins/text_support.js | 2 +- 3 files changed, 55 insertions(+), 46 deletions(-) diff --git a/packages/@ember/deprecated-features/index.ts b/packages/@ember/deprecated-features/index.ts index 32eafaa69e3..df550270453 100644 --- a/packages/@ember/deprecated-features/index.ts +++ b/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'; diff --git a/packages/ember-views/lib/mixins/action_support.js b/packages/ember-views/lib/mixins/action_support.js index 93cd1948ff7..59c4d8ad032 100644 --- a/packages/ember-views/lib/mixins/action_support.js +++ b/packages/ember-views/lib/mixins/action_support.js @@ -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. @@ -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 @@ -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); diff --git a/packages/ember-views/lib/mixins/text_support.js b/packages/ember-views/lib/mixins/text_support.js index b5a1d4274c4..99a5188ea59 100644 --- a/packages/ember-views/lib/mixins/text_support.js +++ b/packages/ember-views/lib/mixins/text_support.js @@ -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,