Skip to content

Commit 2e88adf

Browse files
committed
Converted models to use gjs
1 parent 73ffab2 commit 2e88adf

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

guides/release/models/index.md

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ writing the admin section of a blogging app, which has a feature that
9090
lists the drafts for the currently logged in user.
9191

9292
You 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}
9696
import Component from "@glimmer/component";
9797
import { tracked } from "@glimmer/tracking";
9898
import 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-
124120
This works great for the `list-of-drafts` component. However, your app
125121
is likely made up of many different components. On another page you
126122
may want a component to display the number of drafts. You may be
127123
tempted to copy and paste your existing `willRender` code into the new
128124
component.
129125

130-
```javascript {data-filename=app/components/drafts-button.js}
126+
```gjs {data-filename=app/components/drafts-button.gjs}
131127
import Component from "@glimmer/component";
132128
import { tracked } from "@glimmer/tracking";
133129
import fetch from "fetch";
130+
import { LinkTo } from '@ember/routing';
134131
135132
export 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

154151
Unfortunately, the app will now make two separate requests for the

0 commit comments

Comments
 (0)