-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
RFC: Support for ES accessor
Decorators
#876
base: master
Are you sure you want to change the base?
Conversation
2e84b60
to
7429959
Compare
accessor
Decorators
```js | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking/accessor'; | ||
import { service } from '@ember/service/accessor'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will there be a future RFC to simplify imports?
we have a lot of different import paths now, and it seems this is rapidly growing over time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm planning on an RFC (or set of RFCs, we'll see how it breaks down) that eliminates over 50% of the import paths. The mechanic for that won't surprise anyone: get rid of stuff we don't need anymore!
|
||
Decorators can then layer on top of this. This is more or less what `@tracked`, `@service`, etc. already do—but a spec decorator gets a very different argument, and behaves fairly differently than the legacy decorators implementation. | ||
|
||
We *could* try to absorb that with a single overload, but that has a much higher risk of bugs *and* doesn’t give us any hooks for linting etc. Linting matters because we want to be able to tell people statically (not just with annoying Babel compile errors) that they *must* use `accessor` with this version instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a lint can read the package.json and see what version of package we'd have that supports this, and then autofix-insert accessor
-- making the overload more reasonable, imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is not just the consumer side, it's also the authoring side. Those overloads are already quite heavy, and adding more complexity there substantially ups the challenge of shipping non-buggy code. It's not impossible, but it's far easier to just codemod to the new thing and have much simpler lint rule maintenance as well.
It's also not possible to see purely from the package.json
: we have to support both legacy and spec decorators, so "what version are we on?" doesn't answer the question. That lint rule would have to go parse babel.config.js
and ember-cli-build.js
, and/or boot Ember CLI to get the resolved result of the config.
} | ||
``` | ||
|
||
We want to make sure not to couple *this* change—which just unlocks using the spec decorators—to *that* possibility, which isn’t finalized. We also want this to be trivially codemoddable, and we also plan to deprecate the existing decorators in a future deprecation RFC, so what we ship here is certainly only a transitional path: eventually, regardless of any `@glimmer/reactivity` package, the *primary* imports for these packages should be ES decorators, *not* the legacy decorators. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I think I like where this is going
Co-authored-by: Katie Gengler <katie@kmg.io>
I think there is an alternative path here that may be more ideal in that it ought to enable the ecosystem to more rapidly convert.
Generally this will work for all v1 addons and apps. Get to a version of ember-cli-babel that supports the new decorators, turn on support, prepare non-framework/data decorators, ship it. Where this gets a little dicey is v2-addons since while they still partially compile during app compile based on app babel config, we would want them to ship accessor versions as soon as feasible, even before apps have updated their ember-cli-babel. For this I think we leverage ember-auto-import, which is currently responsible for their final transpilation: converting back from the stage 3 decorators when present if necessary, and doing nothing/leaving be if ember-cli-babel has been configured to use them. Generally most apps are close to latest on ember-auto-import in my experience, and have an easy time upgrading to new minors of it. |
FWIW, I am totally fine with @runspired's alternative proposal here; I definitely do not have time to rewrite or drive it at the moment, but would be happy to see this RFC rewritten with that approach instead, or to close this in favor of a newly-opened RFC with that design. |
@ef4 Does it make sense for you to take this on as champion? |
Yes, I can champion, I expect that will involve doing a pass through the text and changing the place to one more similar to what @runspired is describing. |
Status update on decorators: I expect to supersede this RFC with a rather different one that would offer a more graceful upgrade, because:
|
Rendered
Summary: