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

@classic Decorator #468

Merged
merged 4 commits into from
Jul 19, 2019
Merged

@classic Decorator #468

merged 4 commits into from
Jul 19, 2019

Conversation

pzuraq
Copy link
Contributor

@pzuraq pzuraq commented Mar 15, 2019

own code, or are not passed any arguments other than injections, so for those
classes the usage of `create` is an implementation detail.

These classes will _always_ warn users if they are not decorated with
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

is this a linter warning or a deprecation style warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would be a deprecation style warning, since it’s not information we can actually gather through static analysis. We need to actually run/construct the class to get this information

Copy link
Contributor

Choose a reason for hiding this comment

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

Will it actually be a deprecation, with an identifier and an until field? Or just use warn from 'ember-debug'?

an edge case, such as using `init` in a parent class and `constructor` in a
child class.

This should allow users who wish to adopt native class syntax to do so
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

should this also be a code mod? to add the @classic decorator to each EmberObject class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely! I think a codemod for this would be very helpful

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not so sure. Adding @classic is fairly quick and it might behoove developers to evaluate whether each class needs it manually.

@piotrpalek
Copy link

piotrpalek commented Mar 31, 2019

I think it would be wise to separate EmberObject and native class syntax. There are too many edge cases and weird behaviors. From what I've seen trying to support EmberObject usage with native classes also makes Ember's API unnecessarily complex and worse that it would be otherwise. It would also lead to an easier way of teaching people: "look, this is how Ember is build, but we have this new world where we use native classes and which has different behavior, but it doesn't work for all things that classic Ember supports yet". Worked great for functional components in the React world.

@pzuraq
Copy link
Contributor Author

pzuraq commented Mar 31, 2019

@piotrpalek that's fair, in fact our recommended upgrade path will be:

  • Keep classic components as classic classes until they can be converted to Glimmer components
  • Keep utility classes that extend EmberObject as they are, using classic syntax, until you can convert them directly to native classes.

However for Routes/Controllers/Services, there are already far fewer differences between native class and classic class syntax. Really, the only major ones are using mixins, and using init vs constructor. Given we don't have any native class alternatives for these yet, and that the difference is much much smaller between the two, it makes sense to recommend users to convert over to the newer syntax and incrementally remove these differences. In most cases, I think it will be a pretty straightforward conversion.

There are also some users who must use native class syntax everywhere, such as users who wish to adopt TypeScript. This is different from the React conversion, because in that case, React was converting from one TS compatible form (native classes) to another (functional components). Since those users already exist, and have to deal with these problems anyways, this would provide better tooling for them to detect possible bugs.

@piotrpalek
Copy link

Right, I didn't consider TS users. I can understand the reasons, I've also re-read the RFC and understand it a little better now. My comment was probably less enthusiastic about this because I both didn't understand it enough, as well as a drive-by comment after #467 :) Tl;dr I now consider it a good solution to a tough problem.

Sorry if it came out overly aggressive/negative! 🙏

@pzuraq
Copy link
Contributor Author

pzuraq commented Mar 31, 2019

It's really no problem! This is going to be a tricky transition, and we're trying to strike the right balance - feedback that this could be too complicated is exactly what led to this RFC, and the simplifications in #467 / #451. It's always good to get feedback, thanks for giving us your thoughts 😄

@locks locks added the T-framework RFCs that impact the ember.js library label Apr 2, 2019
@mixonic
Copy link
Sponsor Member

mixonic commented Apr 26, 2019

I believe this RFC needs to identify a package that @classic is imported from

@rwjblue
Copy link
Member

rwjblue commented Jun 28, 2019

I believe this RFC needs to identify a package that @classic is imported from

Ya, totally agree. The current implementation is done in an addon, and I don't see any reason not to keep it that way...

@pzuraq
Copy link
Contributor Author

pzuraq commented Jun 28, 2019

Added the import path and addon name to the RFC, and updated some of the language. We found during implementation that it wasn't possible to restrict all usage of classic APIs in non-classic classes, so we used lint rules for these instead. The general restrictions are the same as before though.

@rwjblue
Copy link
Member

rwjblue commented Jul 12, 2019

👍 from the core team at today's meeting, moving this into final comment period...

@MelSumner
Copy link
Contributor

At today's core team meeting, we have decided to move forward with this RFC. 👍

@MelSumner MelSumner merged commit 3c31716 into emberjs:master Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Final Comment Period T-framework RFCs that impact the ember.js library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants