Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Oct 11, 2024
1 parent 0420db7 commit 25656df
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions ember-resources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"start": "pnpm vite build --watch",
"build": "pnpm vite build",
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
"lint:types": "tsc --noEmit",
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint:js": "eslint . --cache",
"lint:prettier": "prettier --check '**/*.{js,ts}'",
Expand Down
2 changes: 1 addition & 1 deletion ember-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export { resource } from './resource.ts';
export { registerUsable, use } from './use.ts';

// Public Type Utilities
export type { Reactive, ResourceAPI } from './types.ts';
export type { Reactive, Resource, ResourceAPI } from './types.ts';
10 changes: 5 additions & 5 deletions ember-resources/src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { INTERNAL } from './types.ts';
import { registerUsable } from './use.ts';
import { wrapForPlainUsage } from './utils.ts';

import type { InternalFunctionResourceConfig, ResourceFn, ResourceFunction } from './types.ts';
import type { InternalFunctionResourceConfig, Resource, ResourceFunction } from './types.ts';

const TYPE = 'function-based';

Expand Down Expand Up @@ -111,7 +111,7 @@ registerUsable(TYPE, (context: object, config: InternalFunctionResourceConfig) =
* </template>
* ```
*/
export function resource<Value>(setup: ResourceFunction<Value>): Value;
export function resource<Value>(setup: ResourceFunction<Value>): Resource<Value>;

/**
* `resource` is an alternative API to the class-based `Resource`.
Expand Down Expand Up @@ -167,14 +167,14 @@ export function resource<Value>(setup: ResourceFunction<Value>): Value;
* }
* ```
*/
export function resource<Value>(context: object, setup: ResourceFunction<Value>): Value;
export function resource<Value>(context: object, setup: ResourceFunction<Value>): Resource<Value>;

/**
*/
export function resource<Value>(
context: object | ResourceFunction<Value>,
setup?: ResourceFunction<Value>,
): Value | InternalFunctionResourceConfig<Value> | ResourceFn<Value> {
): Value | InternalFunctionResourceConfig<Value> | Resource<Value> {
if (!setup) {
assert(
`When using \`resource\` with @use, ` +
Expand Down Expand Up @@ -205,7 +205,7 @@ export function resource<Value>(
* using vanilla functions as resources without the resource wrapper
*
*/
return internalConfig as unknown as ResourceFn<Value>;
return internalConfig as unknown as Resource<Value>;
}

assert(
Expand Down
2 changes: 2 additions & 0 deletions ember-resources/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,7 @@ export type ResourceFunction<Value = unknown> = (hooks: ResourceAPI) => Value |
*/
export type ResourceFn<Value = unknown> = (hooks: ResourceAPI) => Value;

export type Resource<Value = unknown> = Value & Reactive<Value>;

export type Destructor = () => void;
export type Cache = object;
1 change: 1 addition & 0 deletions test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"scripts": {
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
"lint:types": "glint",
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
Expand Down
2 changes: 1 addition & 1 deletion test-app/tests/type-tests/function-based.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resource } from 'ember-resources';
import { type Resource, resource } from 'ember-resources';
import { expectTypeOf } from 'expect-type';
import { expectType } from 'ts-expect';

Expand Down

0 comments on commit 25656df

Please sign in to comment.