all files / addon/utils/ map-event-to-action.js

100% Statements 9/9
100% Branches 4/4
100% Functions 2/2
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24              75× 73×     75×     75×        
import { invokeAction } from 'ember-invoke-action';
import { assign } from '@ember/polyfills';
 
const defaultOptions = {
  preventDefault: true,
  stopPropagation: false,
};
 
export default function mapEventToAction(actionName, options, ...args) {
  options = assign({}, defaultOptions, options);
  return function(event) {
    if (options.preventDefault) {
      event.preventDefault();
    }
 
    if (options.stopPropagation) {
      event.stopPropagation();
    }
 
    return invokeAction(this, actionName, ...args);
  };
}