@@ -107,15 +107,20 @@ You might be tempted to make the component responsible for fetching that
107
107
data and storing it:
108
108
109
109
``` javascript {data-filename=app/components/list-of-drafts.js}
110
- import Component from ' @ember/component' ;
110
+ import Component from ' @glimmer/component' ;
111
+ import { tracked } from ' @glimmer/tracking' ;
112
+
113
+ export default class ListOfDrafts extends Component {
114
+ @tracked drafts;
115
+
116
+ constructor () {
117
+ super (... arguments );
111
118
112
- export default Component .extend ({
113
- willRender () {
114
119
$ .getJSON (' /drafts' ).then (data => {
115
- this .set ( ' drafts' , data) ;
120
+ this .drafts = data;
116
121
});
117
122
}
118
- });
123
+ }
119
124
```
120
125
121
126
You could then show the list of drafts in your component's template like
@@ -136,21 +141,26 @@ tempted to copy and paste your existing `willRender` code into the new
136
141
component.
137
142
138
143
``` javascript {data-filename=app/components/drafts-button.js}
139
- import Component from ' @ember/component' ;
144
+ import Component from ' @glimmer/component' ;
145
+ import { tracked } from ' @glimmer/tracking' ;
146
+
147
+ export default class DraftsButton extends Component {
148
+ @tracked drafts;
149
+
150
+ constructor () {
151
+ super (... arguments );
140
152
141
- export default Component .extend ({
142
- willRender () {
143
153
$ .getJSON (' /drafts' ).then (data => {
144
- this .set ( ' drafts' , data) ;
154
+ this .drafts = data;
145
155
});
146
156
}
147
- });
157
+ }
148
158
```
149
159
150
160
``` handlebars {data-filename=app/templates/components/drafts-button.hbs}
151
- {{#link-to "drafts" tagName="button"}}
161
+ <LinkTo @route= "drafts" @ tagName="button">
152
162
Drafts ({{this.drafts.length}})
153
- {{/link-to}}
163
+ </LinkTo>
154
164
```
155
165
156
166
Unfortunately, the app will now make two separate requests for the
0 commit comments