Skip to content

Commit

Permalink
fix(types): useResource types now reflect that you *can* make non-rea…
Browse files Browse the repository at this point in the history
…ctive resources

Resolves #48
  • Loading branch information
NullVoxPopuli committed Sep 5, 2021
1 parent fc7b9b4 commit 0b82512
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions addon/-private/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export interface Helper {
}

export type Thunk =
// No Args
| (() => [])
| (() => void)
// plain array / positional args
| (() => Required<ArgsWrapper>['positional'])
// plain named args
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion tests/unit/types-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { LifecycleResource, Resource } from 'ember-resources';
import { LifecycleResource, Resource, useResource } from 'ember-resources';

import type { Named } from 'ember-resources';

Expand All @@ -22,3 +22,14 @@ export function Issue108TypeTest() {

return issue108p2a.args.named?.foo;
}

// https://github.com/NullVoxPopuli/ember-resources/issues/48
export function Issue48TypeTest() {
class TestResource extends Resource {}

return class TestCaseComponent {
test = useResource(this, TestResource, () => {});
testArray = useResource(this, TestResource, () => []);
testVoid = useResource(this, TestResource);
};
}
18 changes: 18 additions & 0 deletions tests/unit/use-resource-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,24 @@ module('useResource', function () {
});
});

test('does not need args', async function (assert) {
class TestResource extends Resource {
foo = 3;
}

class Test {
dataArray = useResource(this, TestResource, () => []);
dataVoid = useResource(this, TestResource, () => {});
dataOmitted = useResource(this, TestResource);
}

let foo = new Test();

assert.equal(foo.dataArray.foo, 3);
assert.equal(foo.dataVoid.foo, 3);
assert.equal(foo.dataOmitted.foo, 3);
});

module('in templates', function (hooks) {
setupRenderingTest(hooks);

Expand Down

0 comments on commit 0b82512

Please sign in to comment.