Skip to content

Commit

Permalink
[BUGFIX beta] Fix no-jQuery EventDispatcher to allow handling multipl…
Browse files Browse the repository at this point in the history
…e element-space actions

Related to emberjs#17874 (comment)
  • Loading branch information
simonihmig committed Apr 7, 2019
1 parent 7da998b commit 18d9087
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,40 @@ moduleFor(
this.assert.ok(doubleClickActionWasCalled, 'the doubleClicked action was called');
}

['@test allows multiple actions for same event on a single element']() {
let clickAction1WasCalled = false;
let clickAction2WasCalled = false;

let ExampleComponent = Component.extend({
actions: {
clicked1() {
clickAction1WasCalled = true;
},
clicked2() {
clickAction2WasCalled = true;
},
},
});

this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: strip`
<a href="#"
{{action "clicked1" on="click"}}
{{action "clicked2" on="click"}}
>click me</a>`,
});

this.render('{{example-component}}');

runTask(() => {
this.$('a').trigger('click');
});

this.assert.ok(clickAction1WasCalled, 'the first clicked action was called');
this.assert.ok(clickAction2WasCalled, 'the second clicked action was called');
}

['@test it should respect preventDefault option if provided']() {
let ExampleComponent = Component.extend({
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,16 @@ export default EmberObject.extend({
return;
}

let result = true;
for (let index = 0; index < actions.length; index++) {
let action = actions[index];

if (action && action.eventName === eventName) {
return action.handler(event);
// return false if any of the action handlers returns false
result = result && action.handler(event);
}
}
return result;
};

// Special handling of events that don't bubble (event delegation does not work).
Expand Down

0 comments on commit 18d9087

Please sign in to comment.