Repository navigation
Update documentation for native imports & signatures - #307
Conversation
jamescdavis
left a comment
There was a problem hiding this comment.
We decided to teach type aliases for args in class-based helper and modifier signatures.
7093d99 to
02f98ce
Compare
| Element: HTMLCanvasElement; | ||
| Args: { | ||
| Positional: Positional; | ||
| Named: RenderOptions; |
| type Positional = Array<number>; | ||
| type Named = { andThenMultiplyBy?: number }; | ||
|
|
||
| export interface AddSignature { |
There was a problem hiding this comment.
Since signatures don't actually need to be exported, is there any value in doing so?
There was a problem hiding this comment.
People sometimes like to do type gymnastics with them, and reverse engineering them from the component type itself generally makes TS fall over. Given the number of times I've had to point people to just exporting the signature type instead of trying to extract it, it seemed reasonable to do it by default.
| @@ -7,8 +7,8 @@ | |||
|
|
|||
| - Ember | |||
There was a problem hiding this comment.
GitHub won't allow me to make comments on parts of the code that didn't change, so I'll keep track of those here:
Lines 3 to 4 in 4fc9b4b
This section is a bit confusing to me because the generic examples aren't super useful. Instead, I would emphasize links to the ember/glimmerx-specific installation guides here and removing the generic .glintrc.yml example. I remember the first time I read this documentation, I missed the sentence about looking for specific example in the sidebar and was confused by a-glint-environment in the example.
There was a problem hiding this comment.
Line 22 in 4fc9b4b
In order to make "getting started" seem super simple for the typical user, I wonder if it would be useful to remove mention of the language server there, since most users won't be working with it directly. I recommend moving the GLS references here to a separate top-level heading for language-server-devs.
There was a problem hiding this comment.
glint/docs/ember/installation.md
Line 1 in 4fc9b4b
Since Glint currently only works with TypeScript, it might be useful to link to ember-cli-typescript here, lest people try to roll their own Ember TypeScript config.
There was a problem hiding this comment.
glint/docs/ember/installation.md
Line 30 in 4fc9b4b
The include config was super useful for my "Converting your Ember App to TS" tutorial, but I found it difficult to find the right combination of include globs (e.g. do you only need to include hbs files or do you have to include all of your TS as well?) and other temporary type changes (a la https://docs.ember-cli-typescript.com/ts/using-ts-effectively#opt-in-unsafety) to make glint pass while in the middle of my migration. It might be useful to include a top-level section with more details here.
There was a problem hiding this comment.
glint/docs/ember/component-signatures.md
Line 32 in 4fc9b4b
NIT: I recommend adding /* ... */ to indicate that code is redacted.
export default class SuperTable<T> extends Component<SuperTableSignature<T>> {/*...*/}`Specifically, in this location, it makes this component look like a template-only component, so the documentation appears to contradict the template-only documentation below. (Reading the code, though, it looks like it would work w/ the "empty" class as shown, but I'm not sure if that's the intent of the documentation since there's a separate section for template-only components.)
There was a problem hiding this comment.
glint/docs/ember/template-registry.md
Line 1 in 4fc9b4b
Consider linking to https://docs.ember-cli-typescript.com/ember-data for context.
There was a problem hiding this comment.
Glint actually works with JS (#199), it's just not documented yet (#208).
Awesome! I do still think a link to e-cli-ts would be useful somewhere since people frequently use them together. My concern is that someone might assume they only need Glint since the overview says "Glint's CLI provides a template-aware tool for performing end-to-end TypeScript typechecking"
| compatible with the DOM element(s) they're ultimately attached to. If no `Element` is specified, it will be a type error | ||
| to set any HTML attributes or modifiers when invoking your component. | ||
|
|
||
| The `Blocks` field specifies the names of any blocks the component yields to, as well as the type of any parameter(s) |
There was a problem hiding this comment.
Need to document how to specify the default block.
| // and a `row` block which will be invoked with each item and | ||
| // its index sequentially. | ||
| Blocks: { | ||
| header: []; |
There was a problem hiding this comment.
The template for this example indicates that the header is optional, but you've removed the ? here. If the ? is included, does Glint actually know about the optional-ness of the block? If so, seems useful to mention here.
There was a problem hiding this comment.
This was a bit of intentional cleanup from a much earlier version of Glint's internals. Today Glint doesn't have a notion of required-ness for blocks, since {{yield}}-ing to a block that your consumer didn't actually pass is just a noop. #149 has a bit more detail on that
| @@ -0,0 +1,151 @@ | |||
| Like components, helpers and modifiers can also have their behavior in templates described by a `Signature` type. | |||
There was a problem hiding this comment.
Very grateful for the addition of this section.
|
|
||
| The recommended approach is to include a declaration in each component, modifier or helper module that adds it to the registry, which is the default export of `@glint/environment-ember-loose/registry`. | ||
|
|
||
| With [first-class component templates][fccts], the day is coming when we won't need this anymore, because any components/helpers/modifiers you use will already be statically in scope, but for now this approach ensures compatibility with the effective global scope of loose-mode templates. |
There was a problem hiding this comment.
This paragraph could use more visual emphasis.
| @@ -2,12 +2,16 @@ Because Ember's template resolution occurs dynamically at runtime today, Glint n | |||
|
|
|||
| The recommended approach is to include a declaration in each component, modifier or helper module that adds it to the registry, which is the default export of `@glint/environment-ember-loose/registry`. | |||
There was a problem hiding this comment.
This section could use an example of what the glint error message will look like if you forget to add something to the registry so that Google will point someone to this documentation when that happens.
| @@ -5,19 +5,34 @@ Here's an example that provides types for the `page-title` helper and the `Welco | |||
| {% code title="types/global.d.ts" %} | |||
There was a problem hiding this comment.
This section could use another reference to https://github.com/Gavant/glint-template-types.
| ``` | ||
|
|
||
| You can also use the `glint` command locally with the `--watch` flag to monitor your project as you work! | ||
| You can [use the `glint` executable in CI][using-glint] to ensure you maintain type safety in your templates. You can also use the `glint` command locally with the `--watch` flag to monitor your project as you work! |
There was a problem hiding this comment.
The wording here is 🤔 – "maintain type safety in your templates" sort of reads to me as if it is only for templates. Trying to think of a rephrasing and so far failing, though.
|
Thanks for the feedback, everyone! I REALLY appreciate the attention on the docs ❤️ In the interest of keeping the scope of this PR from blowing out (despite what the diff looks like, it really is 95% find/replacing code snippets and moving existing prose around between I would love to review PRs incorporating the other suggestions here (as well as anything else that can be improved!), but I know you're all busy and have already devoted time to writing up your commentary here, so I'll plan to come back and revisit after I travel next week if better writers than me don't get to it first 🙂 |
Co-authored-by: Krystan HuffMenne <krystan@tilde.io>
I believe as of typed-ember#307 we don't need this anymore!?
Currently all of our documentation is framed in terms of the custom re-exports we've had to use for much for Glint's lifetime, but with #283 native imports are now an option, and with #304 those imports will be the only option. Accordingly, this PR updates the documentation site to use native imports and signatures in all of its example snippets.
This also removes the bulk of the contents of our README (from which the doc site contents were originally copied) in favor of nudging folks toward the more structured version of the content and avoiding the need to maintain the same information two places.