yarn add ember-event-helpers
# if you're on ember-source 3.9 or below
yarn add ember-on-modifier ember-fn-helper-polyfillThis is the safest of the codemods.
npx ember-template-recast app/ -t \
https://raw.githubusercontent.com/lennyburdette/ember-action-codemods/master/src/action-modifiers.jsSwitching from event properties to Ember modifiers can have subtle behavior changes regarding event ordering!
See https://developer.squareup.com/blog/deep-dive-on-ember-events/ for a comprehensive rundown.
npx ember-template-recast app/ -t \
https://raw.githubusercontent.com/lennyburdette/ember-action-codemods/master/src/event-properties.jsRequires Ember.js 3.10 and above. This will no-op if your action names conflict with existing ember component functions.
If you're converting to native classes, this is unnecessary (you're already
using the @action decorator).
npx jscodeshift app/ -t \
https://raw.githubusercontent.com/lennyburdette/ember-action-codemods/master/src/action-decorators.jsIf you're not using the actions hash in components and controllers, this is
safe to do.
npx ember-template-recast app/ -t \
https://raw.githubusercontent.com/lennyburdette/ember-action-codemods/master/src/string-actions.jsCheck out the tests!
-
<button {{action foo}}>→<button {{on "click" (prevent-default foo)}}> -
<button onclick={{action foo}}>→<button {{on "click" (prevent-default foo)}}> -
actions: { foo() {} }
→
foo: action(function() {})
-
<button {{on "click" (action "foo")}}>→<button {{on "click" this.foo}}>
- Remove uses of the
(action)helper once there's a canonical way to handlevalue=,target=, andallowedKeys=.