Skip to content

Commit 7c7fa3f

Browse files
committed
docs(formatting): update TS component file rules and add example
Clarify import from @glimmer/component with exact syntax and emphasize using interface Signature. Add guidance to group and alphabetize @service registrations. Provide an updated example showing typed @service usage, multiple getters, and an action method to illustrate best practices for component implementation.
1 parent a83a706 commit 7c7fa3f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

.cursor/rules/formatting-component-files.mdc

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ alwaysApply: true
44
When creating components, follow these rules:
55

66
- Use typescript (`.ts`) files
7-
- Import from `@glimmer/component`
7+
- Import from `@glimmer/component` like this: `import Component from '@glimmer/component';`
88
- Use `interface Signature { ... }` to define the component's signature
99
- `class` doesn't have to be in `Args`, ember automatically forwards native args like `class`, `id` etc. to the component
1010
- Ensure the component is registered w/ Glint using `declare module ...`
11-
11+
- Ensure service registrations using `@service` are grouped together and sorted alphabetically
1212

1313
Example:
1414

1515
```ts
1616
import Component from '@glimmer/component';
17+
import { service } from '@ember/service';
18+
import type RouterService from '@ember/routing/router-service';
19+
import type Store from '@ember-data/store';
1720

1821
interface Signature {
1922
Element: HTMLDivElement;
@@ -25,9 +28,21 @@ interface Signature {
2528
}
2629

2730
export default class TrackPageCard extends Component<Signature> {
31+
@service declare router: RouterService;
32+
@service declare store: Store;
33+
2834
get property1() {
2935
return 'dummy';
3036
}
37+
38+
get property2() {
39+
return this.store.peekAll('course');
40+
}
41+
42+
@action
43+
handleClick() {
44+
this.router.transitionTo('course', 'redis');
45+
}
3146
}
3247

3348
declare module '@glint/environment-ember-loose/registry' {

0 commit comments

Comments
 (0)