Use plain functions as modifiers. Polyfill for RFC: 757 | Default Modifier Manager
- Ember.js v3.25 or above
- Ember CLI v3.25 or above
- Node.js v14 or above
- ember-auto-import v1 or above
- embroider-optimized
ember install ember-functions-as-modifiers-polyfill
Define a function (doesn't have to be in a component)
import Component from '@glimmer/component';
export default class MyComponent extends Component {
myModifier = (element, x) => {
let handler = () => console.log(x); // -> 3
element.addEventListener('click', handler);
return () => element.removeEventListener('click', handler);
}
}
Named arguments will all be grouped together in the last argument of the helper:
import Component from '@glimmer/component';
export default class MyComponent extends Component {
doStuff = (element, x, options) => {
let handler = () => console.log(x, options.optionA, options.optionB); // -> 3 2 3
element.addEventListener('click', handler);
return () => element.removeEventListener('click', handler);
};
}
See the Contributing guide for details.
This project is licensed under the MIT License.