Skip to content

Commit d7941f4

Browse files
fix(readme): all code samples now include imports from ember-resources
resolves #87
2 parents 7b4b406 + c4ea274 commit d7941f4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class MyClass {
6565
`useResource` takes a `LifecycleResource` and an args thunk.
6666

6767
```ts
68+
import { useResource } from 'ember-resources';
69+
6870
class MyClass {
6971
data = useResource(this, SomeResource, () => [arg list]);
7072
}
@@ -88,6 +90,8 @@ A concurrency task accessed via `useTask` is only "ran" when accessed, and autom
8890
when it needs to.
8991

9092
```ts
93+
import { useTask } from 'ember-resources';
94+
9195
class MyClass {
9296
myData = useTask(this, this._myTask, () => [args, to, task])
9397

@@ -112,6 +116,8 @@ An example of this might be an object that you want to have perform some
112116
complex or async behavior
113117

114118
```ts
119+
import { LifecycleResource } from 'ember-resources';
120+
115121
class MyResource extends LifecycleResource {
116122
@tracked isRunning;
117123
@tracked error;
@@ -150,6 +156,8 @@ class MyResource extends LifecycleResource {
150156

151157
Using your custom Resource would look like
152158
```ts
159+
import { useResource } from 'ember-resources';
160+
153161
class ContainingClass {
154162
data = useResource(this, MyResource, () => [this.ids])
155163
}
@@ -163,6 +171,8 @@ invocation's return value as an argument to the next time the function is called
163171

164172
Example:
165173
```ts
174+
import { useFunction } from 'ember-resources';
175+
166176
class StarWarsInfo {
167177
// access result on info.value
168178
info = useFunction(this, async (state, ...args) => {
@@ -198,6 +208,8 @@ To help prevent accidental async footguns, even if a function is synchronous, it
198208
asynchronously, therefor, the thunk cannot be avoided.
199209

200210
```ts
211+
import { useResource } from 'ember-resources';
212+
201213
class MyClass {
202214
@tracked num = 3;
203215

@@ -321,6 +333,8 @@ There are two approaches:
321333
### `new` the resource directly
322334

323335
```ts
336+
import { LifecycleResource } from 'ember-resources';
337+
324338
test('my test', function(assert) {
325339
class MyResource extends LifecycleResource {
326340
// ...
@@ -343,6 +357,8 @@ the resource instance.
343357
If, instead of creating `MyResource` directly, like in the example above,
344358
it is wrapped in a test class and utilizes `useResource`:
345359
```ts
360+
import { useResource } from 'ember-resources';
361+
346362
class TestContext {
347363
data = useResource(this, MyResource, () => { ... })
348364
}
@@ -356,6 +372,8 @@ time for the framework to propagate changes to all the reactive bits.
356372
Example:
357373

358374
```ts
375+
import { LifecycleResource, useResource } from 'ember-resources';
376+
359377
test('my test', async function (assert) {
360378
class Doubler extends LifecycleResource<{ positional: [number] }> {
361379
get num() {

0 commit comments

Comments
 (0)