Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation guide for (action) / {{action}} #1377

Merged
merged 7 commits into from
May 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update deprecate-template-action.md
  • Loading branch information
achambers committed Apr 17, 2024
commit 9eb6905945a269515bf5496c4dc09413699a9398
24 changes: 20 additions & 4 deletions content/ember/v5/deprecate-template-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Before:
</button>
```

After

After:
```handlebars
<button type="button" {{on 'click' this.plusOne}}>
Click Me
</button>
```
or, if `plusOne` is passed in as an argument

or, if `plusOne` is passed in as an argument:
```handlebars
<button type="button" {{on 'click' @plusOne}}>
Click Me
Expand All @@ -29,6 +29,8 @@ or, if `plusOne` is passed in as an argument

If the `plusOne` action is in an actions object, it needs to move out:
NullVoxPopuli marked this conversation as resolved.
Show resolved Hide resolved

#### For Glimmer components

Before:
```javascript
import Component from '@glimmer/component';
Expand All @@ -41,6 +43,7 @@ export default class Demo extends Component {
}
}
```

After:
```javascript
import Component from '@glimmer/component';
Expand All @@ -56,11 +59,17 @@ export default class Demo extends Component {

or

#### For Classic Components with native classes

Before:
```javascript
import Component from '@ember/component';

export default class Demo extends Component {
doMath() {
this.send('plusOne');
}

actions = {
plusOne() {
/* ... */
Expand All @@ -75,14 +84,21 @@ import Component from '@ember/component';
import { action } from '@ember/object';

export default class Demo extends Component {
doMath() {
this.plusOne();
}

@action
plusOne() {
/* ... */
}
}
```

or

#### For Classic Components with EmberObject.extend

Before:
```javascript
import Component from '@ember/component';
Expand All @@ -108,7 +124,7 @@ export default Component.extend({
})
```

If `(action)` or `{{action}}` is passed a string, it's _possible_ that the referenced method is declared on the caller, and _not_ the immediate component -- that is, `(action)` and `{{action}}` bubble up the render tree.
If `(action)` or `{{action}}` is passed a string, it's _possible_ that the referenced method is declared on the caller, and _not_ the immediate component -- that is, `(action)` and `{{action}}` bubble up the render tree from route templates -> controllers -> routes.

Note that `@action` is completely different from `(action)` or `{{action}}` (and is partly a motivator for deprecating `(action)` and `{{action}}`, to reduce ambiguity).

Expand Down
Loading