You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0779-first-class-component-templates.md
+52-1Lines changed: 52 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -642,7 +642,58 @@ The current blueprints support generating a backing class for any existing compo
642
642
643
643
2. Reimplement the blueprint using an ASTtransform (which we have prior art for: route generation uses that approach), to add a backing classfor an existing default exportinthemodule.
644
644
645
-
We should take (1) here as a default starting point, while encouraging the community to implement (2) if interested.
645
+
(We should take (1) here as a default starting point, while encouraging the community to implement (2) if interested.)
646
+
647
+
We should also update the name of the classgeneratedfor a component class. The default behavior of today's blueprint when generating a component is to suffix the class name with `Component`. Thus, running `ember generate component greeting --component-class=@glimmer/component` will produce a class named `GreetingComponent`.[^ts-component-name]
648
+
649
+
There was room for debate about whether this made sense for naming component classes up till now, since the invocation name was based on the file name (using Ember's resolution rules) and *not* the classname. Now, though, it *will* be based on the imported name, and the standard behavior of auto-import tooling is to import classes by their full name—whether the item is a named export or a default export. When a user goes to autocomplete `Greeting` (e.g. in [Glint][glint]), they will end up with `GreetingComponent`, leading to this sort of thing if they don’t rename it:
650
+
651
+
```js
652
+
import GreetingComponent from './greeting';
653
+
654
+
<template>
655
+
<GreetingComponent @name={{@user.name}} />
656
+
</template>
657
+
```
658
+
659
+
This is obviously undesirable, but avoiding this will mean mean renaming locally after the autocomplete works. That renaming operation is needless papercut in the best case of importing a default export. Itrisestothelevelofasignificantannoyancewhenusingnamedimports:
Accordingly, we should switch to generating *without* a class name: `ember generate component greeting --component-class=@glimmer/component` should produce a class named `Greeting`, *not* `GreetingComponent`. The generated names for routes, services, and controllers can remain as they are, since they are never invoked this way.
695
+
696
+
[^ts-component-name]: In TypeScript, this also extends to `GreetingComponentArgs` (or, with [RFC #0748][rfc-0748], something like `GreetingComponentSignature`), which gets *really* unwieldy!
0 commit comments