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

Deprecate the (action) template helper and modifier #1006

Merged
merged 9 commits into from
Mar 8, 2024

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Feb 13, 2024

Propose deprecating the (action) template helper and modifier

Rendered

Summary

This pull request is proposing a new RFC.

To succeed, it will need to pass into the Exploring Stage), followed by the Accepted Stage.

A Proposed or Exploring RFC may also move to the Closed Stage if it is withdrawn by the author or if it is rejected by the Ember team. This requires an "FCP to Close" period.

An FCP is required before merging this PR to advance to Accepted.

Upon merging this PR, automation will open a draft PR for this RFC to move to the Ready for Released Stage.

Exploring Stage Description

This stage is entered when the Ember team believes the concept described in the RFC should be pursued, but the RFC may still need some more work, discussion, answers to open questions, and/or a champion before it can move to the next stage.

An RFC is moved into Exploring with consensus of the relevant teams. The relevant team expects to spend time helping to refine the proposal. The RFC remains a PR and will have an Exploring label applied.

An Exploring RFC that is successfully completed can move to Accepted with an FCP is required as in the existing process. It may also be moved to Closed with an FCP.

Accepted Stage Description

To move into the "accepted stage" the RFC must have complete prose and have successfully passed through an "FCP to Accept" period in which the community has weighed in and consensus has been achieved on the direction. The relevant teams believe that the proposal is well-specified and ready for implementation. The RFC has a champion within one of the relevant teams.

If there are unanswered questions, we have outlined them and expect that they will be answered before Ready for Release.

When the RFC is accepted, the PR will be merged, and automation will open a new PR to move the RFC to the Ready for Release stage. That PR should be used to track implementation progress and gain consensus to move to the next stage.

Checklist to move to Exploring

  • The team believes the concepts described in the RFC should be pursued.
  • The label S-Proposed is removed from the PR and the label S-Exploring is added.
  • The Ember team is willing to work on the proposal to get it to Accepted

Checklist to move to Accepted

  • This PR has had the Final Comment Period label has been added to start the FCP
  • The RFC is announced in #news-and-announcements in the Ember Discord.
  • The RFC has complete prose, is well-specified and ready for implementation.
    • All sections of the RFC are filled out.
    • Any unanswered questions are outlined and expected to be answered before Ready for Release.
    • "How we teach this?" is sufficiently filled out.
  • The RFC has a champion within one of the relevant teams.
  • The RFC has consensus after the FCP period.

@github-actions github-actions bot added the S-Proposed In the Proposed Stage label Feb 13, 2024
@achambers
Copy link
Contributor

RFC Review (1) are happy for this to go to exploring. Over to RFC Review (2).

/cc @kategengler (just to bubble this up)

@NullVoxPopuli NullVoxPopuli changed the title Deprecate the (action) template-helper Deprecate the (action) template helper and modifier Feb 16, 2024
After

```hbs
<SomeComponent @update={{this.plusOne}} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may need to note that plusOne on the class will need the @action decorator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

action decorator is only needed for {{action compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've mentioned this once during the first scenario -- do you think it's enough?

## Unresolved questions

- Could there be a codemod?
_Potentially_ for action usage that references `this.properties`. For string actions, it's impossible.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And at minima the codemod would be able to emit warnings in that case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea

@ef4 ef4 added S-Exploring In the Exploring RFC Stage Final Comment Period and removed S-Proposed In the Proposed Stage labels Feb 23, 2024
@a13o
Copy link

a13o commented Feb 24, 2024

Does this end up implicitly deprecating the classic class syntax? Is there a migration path for this kind of component which doesn't involve porting to ES6 class syntax first?

import Component from '@ember/component';
export default Component.extend({
  actions: {
    doThing() {
      this.thing;
    }
  }
});
<button {{action "doThing"}}>do</button>

Actually, is there even a way to write EmberComponents with ES6 class syntax? Does this proposal end up deprecating EmberComponents?

@NullVoxPopuli
Copy link
Contributor Author

NullVoxPopuli commented Feb 24, 2024

Is there a migration path for this kind of component which doesn't involve porting to ES6 class syntax first?

yes! (see below)

Does this proposal end up deprecating EmberComponents?

It does not -- you can remain in the classic world by migrating to this.

import Component from '@ember/component';
import { action, set } from '@ember/object';

Component.extend({
  count: 0,
  increment: action(function () {
    set(this, 'count', this.count + 1);
  }),
});

Interactive demo here

is there even a way to write EmberComponents with ES6 class syntax?

There is! (and this is preferred!, and what was recommended during the era leading up to Octane, iirc)

looks like this:

import Component from '@ember/component';
import { tracked } from '@glimmer/tracking';

export default class Demo extends Component {
  @tracked count = 0;
  increment = () => this.count++;
}

Interactive demo here

And even with ember components, you can use the latest format, GJS, which looks like this:

import Component from '@ember/component';
import { tracked } from '@glimmer/tracking';
import { on } from '@ember/modifier';

export default class Demo extends Component {
  @tracked count = 0;
  increment = () => this.count++;

  <template>
    <p>Clicked: {{this.count}}</p>
  
    <button {{on 'click' this.increment}}>click</button>
  </template>
}

Personally, I'd opt to go straight to gjs (and glimmer) at that point (IFF there are sufficient tests for the component that is -- I like safe migrations 😅 )

import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { on } from '@ember/modifier';

export default class HelloWorld extends Component {
  @tracked count = 0;

  increment = () => this.count += 1;

  <template>
    <p>Count: {{this.count}}</p>

    <button {{on "click" this.increment}}>Click</button>
  </template>
}

(note that this is nearly identical (DX-wise) to the ember component version, except you'll inherently get a slight perf boost, due to glimmer components just being less complex)

@a13o
Copy link

a13o commented Feb 24, 2024

Phew! Porting all those classic components to the prop: action() syntax isn't so bad.

For porting them to ES6, the next smallest hop would probably be something like this

@kategengler
Copy link
Member

ember-native-class-codemod will get your ember components to es6 syntax, for the most part.

NullVoxPopuli added a commit to NullVoxPopuli/ember.js that referenced this pull request Mar 5, 2024
NullVoxPopuli added a commit to NullVoxPopuli/deprecation-app that referenced this pull request Mar 5, 2024
Comment on lines +144 to +179
Before:
```js
import Component from '@glimmer/component';

export default class Demo extends Component {
actions = {
plusOne() {
/* ... */
}
}
}
```
or
```js
import Component from '@ember/component';

export default class Demo extends Component {
actions = {
plusOne() {
/* ... */
}
}
}
```
or
```js
import Component from '@ember/component';

export default Component.extend({
actions: {
plusOne() {
/* ... */
}
}
})
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we should have independent "after" examples for each of these before cases. The way this is written right now suggests that you might need to upgrade to glimmer class-based components to get around this deprecation, which isn't technically true (even if encouraged 😂)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, but this sounds like a detail for the deprecation guide PR 🎉

https://github.com/emberjs/rfcs/blob/master/deprecation-template.md#transition-path

states that:

enough detail for someone who uses the deprecated functionality to understand, for someone to write the deprecation guide, and for someone familiar with the implementation to implement.

So since whether or not to choose @ember/component or @glimmer/component is a point-in-time and learning based decision, I think it makes sense to defer to the deprecation guide PR to work out how all that is formatted, the prose, etc.

@ef4 ef4 merged commit 57018df into master Mar 8, 2024
8 checks passed
@delete-merged-branch delete-merged-branch bot deleted the deprecate-action-template-helper branch March 8, 2024 20:03
NullVoxPopuli added a commit to NullVoxPopuli/ember.js that referenced this pull request Mar 26, 2024
NullVoxPopuli added a commit to NullVoxPopuli/ember.js that referenced this pull request Mar 26, 2024
NullVoxPopuli added a commit to NullVoxPopuli/ember.js that referenced this pull request Mar 26, 2024
ef4 added a commit that referenced this pull request Apr 26, 2024
Advance RFC #1006 `"Deprecate (action) template helper and {{action}} modifier."` to Stage Ready for Release
ef4 added a commit that referenced this pull request Jun 14, 2024
Advance RFC #1006 `"Deprecate (action) template helper and {{action}} modifier."` to Stage Released
ef4 added a commit that referenced this pull request Aug 30, 2024
Advance RFC #1006 `"Deprecate (action) template helper and {{action}} modifier."` to Stage Recommended
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Final Comment Period S-Exploring In the Exploring RFC Stage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants