@@ -90,9 +90,9 @@ writing the admin section of a blogging app, which has a feature that
9090lists the drafts for the currently logged in user.
9191
9292You might be tempted to make the component responsible for fetching that
93- data and storing it:
93+ data and storing it and showing the list of drafts, like this :
9494
95- ``` javascript {data-filename=app/components/list-of-drafts.js }
95+ ``` gjs {data-filename=app/components/list-of-drafts.gjs }
9696import Component from "@glimmer/component";
9797import { tracked } from "@glimmer/tracking";
9898import fetch from "fetch";
@@ -107,30 +107,27 @@ export default class ListOfDraftsComponent extends Component {
107107 this.drafts = data;
108108 });
109109 }
110+ <template>
111+ <ul>
112+ {{#each this.drafts key="id" as |draft|}}
113+ <li>{{draft.title}}</li>
114+ {{/each}}
115+ </ul>
116+ </template>
110117}
111118```
112119
113- You could then show the list of drafts in your component's template like
114- this:
115-
116- ``` handlebars {data-filename=app/components/list-of-drafts.hbs}
117- <ul>
118- {{#each this.drafts key="id" as |draft|}}
119- <li>{{draft.title}}</li>
120- {{/each}}
121- </ul>
122- ```
123-
124120This works great for the ` list-of-drafts ` component. However, your app
125121is likely made up of many different components. On another page you
126122may want a component to display the number of drafts. You may be
127123tempted to copy and paste your existing ` willRender ` code into the new
128124component.
129125
130- ``` javascript {data-filename=app/components/drafts-button.js }
126+ ``` gjs {data-filename=app/components/drafts-button.gjs }
131127import Component from "@glimmer/component";
132128import { tracked } from "@glimmer/tracking";
133129import fetch from "fetch";
130+ import { LinkTo } from '@ember/routing';
134131
135132export default class DraftsButtonComponent extends Component {
136133 @tracked drafts;
@@ -142,13 +139,13 @@ export default class DraftsButtonComponent extends Component {
142139 this.drafts = data;
143140 });
144141 }
145- }
146- ```
147142
148- ``` handlebars {data-filename=app/components/drafts-button.hbs}
149- <LinkTo @route="drafts">
150- Drafts ({{this.drafts.length}})
151- </LinkTo>
143+ <template>
144+ <LinkTo @route="drafts">
145+ Drafts ({{this.drafts.length}})
146+ </LinkTo>
147+ </template>
148+ }
152149```
153150
154151Unfortunately, the app will now make two separate requests for the
0 commit comments