Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow accessing encapsulated task state #5

Merged
merged 1 commit into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Task, task, taskGroup } from 'ember-concurrency';
import {
Task,
TaskInstance,
EncapsulatedTask,
EncapsulatedTaskProperty,
EncapsulatedTaskState,
task,
taskGroup,
} from 'ember-concurrency';

declare module 'ember-concurrency' {
export type AsyncTaskFunction<T, Args extends any[]> = (...args: Args) => Promise<T>;
Expand All @@ -9,21 +17,40 @@ declare module 'ember-concurrency' {
export type AsyncTaskFunctionReturnType<T extends AsyncTaskFunction<any, any[]>> =
T extends (...args: any[]) => Promise<infer R> ? R : unknown;

export type TaskForAsyncTaskFunction<T extends AsyncTaskFunction<any, any[]>> =
Task<AsyncTaskFunctionReturnType<T>, AsyncTaskFunctionArgs<T>>;

export type TaskInstanceForAsyncTaskFunction<T extends AsyncTaskFunction<any, any[]>> =
TaskInstance<AsyncTaskFunctionReturnType<T>>;

export interface AsyncEncapsulatedTaskDescriptor<T, Args extends any[]> {
perform(...args: Args): Promise<T>;
}

export type AsyncEncapsulatedTaskDescriptorArgs<T extends AsyncEncapsulatedTaskDescriptor<any, any[]>> =
T extends (...args: infer A) => Promise<any> ? A : [];
T extends { perform(...args: infer A): Promise<any> } ? A : [];

export type AsyncEncapsulatedTaskDescriptorReturnType<T extends AsyncEncapsulatedTaskDescriptor<any, any[]>> =
T extends (...args: any[]) => Promise<infer R> ? R : unknown;
T extends { perform(...args: any[]): Promise<infer R> } ? R : unknown;

export type AsyncEncapsulatedTaskState<T extends object> = EncapsulatedTaskState<T>;

export type TaskForAsyncEncapsulatedTaskDescriptor<T extends AsyncEncapsulatedTaskDescriptor<any, any[]>> =
EncapsulatedTask<
AsyncEncapsulatedTaskDescriptorReturnType<T>,
AsyncEncapsulatedTaskDescriptorArgs<T>,
AsyncEncapsulatedTaskState<T>
>;

export type TaskInstanceForAsyncEncapsulatedTaskDescriptor<T extends AsyncEncapsulatedTaskDescriptor<any, any[]>> =
TaskInstance<AsyncEncapsulatedTaskDescriptorReturnType<T>> & AsyncEncapsulatedTaskDescriptorArgs<T>;

function task<T extends AsyncTaskFunction<any, any[]>>(taskFn: T):
TaskProperty<AsyncTaskFunctionReturnType<T>, AsyncTaskFunctionArgs<T>>;
function task<T extends AsyncEncapsulatedTaskDescriptor<any, any[]>>(taskFn: T):
TaskProperty<AsyncEncapsulatedTaskDescriptorReturnType<T>, AsyncEncapsulatedTaskDescriptorArgs<T>>;

function taskGroup<T extends AsyncTaskFunction<any, any[]>>(taskFn: T):
TaskGroup<AsyncTaskFunctionReturnType<T>>;
EncapsulatedTaskProperty<
AsyncEncapsulatedTaskDescriptorReturnType<T>,
AsyncEncapsulatedTaskDescriptorArgs<T>,
AsyncEncapsulatedTaskState<T>
>;
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"ember-cli-babel-plugin-helpers": "^1.1.0",
"ember-cli-htmlbars": "^4.3.1"
},
"peerDependencies": {
"ember-concurrency": "^1.2.1"
},
"devDependencies": {
"@babel/core": "^7.10.2",
"@babel/plugin-syntax-class-properties": "^7.10.1",
Expand All @@ -49,7 +52,7 @@
"ember-cli-inject-live-reload": "^2.0.2",
"ember-cli-sri": "^2.1.1",
"ember-cli-uglify": "^3.0.0",
"ember-concurrency": "^1.2.0",
"ember-concurrency": "^1.2.1",
"ember-concurrency-decorators": "^2.0.0",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.1",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5113,10 +5113,10 @@ ember-concurrency-decorators@^2.0.0:
ember-cli-htmlbars "^4.3.1"
ember-cli-typescript "^3.1.4"

ember-concurrency@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/ember-concurrency/-/ember-concurrency-1.2.0.tgz#f8d09ff035ba7652f01de198b9e16424ef2b8522"
integrity sha512-XEKleKlcJQOTbMHEbEtIYF/VXSJDVB8H3pRFY5qmGqGujvpLaJY0GCQ6xtnTDdmSDkBO77FJ9o36GL7iwyqn6g==
ember-concurrency@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/ember-concurrency/-/ember-concurrency-1.2.1.tgz#54fb234579638c5c43d4153a4e14567fe2b2e325"
integrity sha512-6zlK3BndPPZlSVWq6xBohwobpDKrI58nMMDfD8OqjoeBwnaznuyVHJqDZ46NRJrvSqYX6R96XBBVpDGCCcbK+w==
dependencies:
ember-cli-babel "^7.7.3"
ember-compatibility-helpers "^1.2.0"
Expand Down