@@ -65,6 +65,8 @@ class MyClass {
65
65
` useResource ` takes a ` LifecycleResource ` and an args thunk.
66
66
67
67
``` ts
68
+ import { useResource } from ' ember-resources' ;
69
+
68
70
class MyClass {
69
71
data = useResource (this , SomeResource , () => [arg list ]);
70
72
}
@@ -88,6 +90,8 @@ A concurrency task accessed via `useTask` is only "ran" when accessed, and autom
88
90
when it needs to.
89
91
90
92
``` ts
93
+ import { useTask } from ' ember-resources' ;
94
+
91
95
class MyClass {
92
96
myData = useTask (this , this ._myTask , () => [args , to , task ])
93
97
@@ -112,6 +116,8 @@ An example of this might be an object that you want to have perform some
112
116
complex or async behavior
113
117
114
118
``` ts
119
+ import { LifecycleResource } from ' ember-resources' ;
120
+
115
121
class MyResource extends LifecycleResource {
116
122
@tracked isRunning;
117
123
@tracked error;
@@ -150,6 +156,8 @@ class MyResource extends LifecycleResource {
150
156
151
157
Using your custom Resource would look like
152
158
``` ts
159
+ import { useResource } from ' ember-resources' ;
160
+
153
161
class ContainingClass {
154
162
data = useResource (this , MyResource , () => [this .ids ])
155
163
}
@@ -163,6 +171,8 @@ invocation's return value as an argument to the next time the function is called
163
171
164
172
Example:
165
173
``` ts
174
+ import { useFunction } from ' ember-resources' ;
175
+
166
176
class StarWarsInfo {
167
177
// access result on info.value
168
178
info = useFunction (this , async (state , ... args ) => {
@@ -198,6 +208,8 @@ To help prevent accidental async footguns, even if a function is synchronous, it
198
208
asynchronously, therefor, the thunk cannot be avoided.
199
209
200
210
``` ts
211
+ import { useResource } from ' ember-resources' ;
212
+
201
213
class MyClass {
202
214
@tracked num = 3 ;
203
215
@@ -321,6 +333,8 @@ There are two approaches:
321
333
### ` new ` the resource directly
322
334
323
335
``` ts
336
+ import { LifecycleResource } from ' ember-resources' ;
337
+
324
338
test (' my test' , function (assert ) {
325
339
class MyResource extends LifecycleResource {
326
340
// ...
@@ -343,6 +357,8 @@ the resource instance.
343
357
If, instead of creating ` MyResource ` directly, like in the example above,
344
358
it is wrapped in a test class and utilizes ` useResource ` :
345
359
``` ts
360
+ import { useResource } from ' ember-resources' ;
361
+
346
362
class TestContext {
347
363
data = useResource (this , MyResource , () => { ... })
348
364
}
@@ -356,6 +372,8 @@ time for the framework to propagate changes to all the reactive bits.
356
372
Example:
357
373
358
374
``` ts
375
+ import { LifecycleResource , useResource } from ' ember-resources' ;
376
+
359
377
test (' my test' , async function (assert ) {
360
378
class Doubler extends LifecycleResource <{ positional: [number ] }> {
361
379
get num() {
0 commit comments