From b327e879b4f6b01c297e2879c850c1115df21d46 Mon Sep 17 00:00:00 2001 From: Gavin Joyce Date: Tue, 24 Jan 2017 14:11:43 +0000 Subject: [PATCH] [BUGFIX beta] further simplify action event handler --- .../ember-glimmer/lib/modifiers/action.js | 22 ++-------------- .../lib/system/event_dispatcher.js | 25 +++++-------------- 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/packages/ember-glimmer/lib/modifiers/action.js b/packages/ember-glimmer/lib/modifiers/action.js index c18e0774065..bd3c77c6764 100644 --- a/packages/ember-glimmer/lib/modifiers/action.js +++ b/packages/ember-glimmer/lib/modifiers/action.js @@ -38,34 +38,16 @@ export let ActionHelper = { registerAction(actionState) { let { actionId } = actionState; - let actions = ActionManager.registeredActions[actionId]; - if (!actions) { - actions = ActionManager.registeredActions[actionId] = []; - } - - actions.push(actionState); + ActionManager.registeredActions[actionId] = actionState; return actionId; }, unregisterAction(actionState) { let { actionId } = actionState; - let actions = ActionManager.registeredActions[actionId]; - - if (!actions) { - return; - } - let index = actions.indexOf(actionState); - - if (index !== -1) { - actions.splice(index, 1); - } - - if (actions.length === 0) { - delete ActionManager.registeredActions[actionId]; - } + delete ActionManager.registeredActions[actionId]; } }; diff --git a/packages/ember-views/lib/system/event_dispatcher.js b/packages/ember-views/lib/system/event_dispatcher.js index d3183d36e66..90732baa9bc 100644 --- a/packages/ember-views/lib/system/event_dispatcher.js +++ b/packages/ember-views/lib/system/event_dispatcher.js @@ -219,30 +219,17 @@ export default EmberObject.extend({ rootElement.on(`${event}.ember`, '[data-ember-action]', evt => { let attributes = evt.currentTarget.attributes; - let attributeCount = attributes.length; - let actions = []; - for (let i = 0; i < attributeCount; i++) { + for (let i = 0; i < attributes.length; i++) { let attr = attributes.item(i); let attrName = attr.name; - if (attrName.indexOf('data-ember-action-') === 0) { - actions = actions.concat(ActionManager.registeredActions[attr.value]); - } - } - - // We have to check for actions here since in some cases, jQuery will trigger - // an event on `removeChild` (i.e. focusout) after we've already torn down the - // action handlers for the view. - if (actions.length === 0) { - return; - } - - for (let index = 0; index < actions.length; index++) { - let action = actions[index]; + if (attrName.lastIndexOf('data-ember-action-', 0) !== -1) { + let action = ActionManager.registeredActions[attr.value]; - if (action && action.eventName === eventName) { - return action.handler(evt); + if (action.eventName === eventName) { + action.handler(evt); + } } } });