@@ -11,6 +11,12 @@ export type TaskFunctionArgs<T extends TaskFunction<any, any[]>> =
11
11
export type TaskFunctionReturnType < T extends TaskFunction < any , any [ ] > > =
12
12
T extends ( ...args : any [ ] ) => TaskGenerator < infer R > ? R : unknown ;
13
13
14
+ export type TaskForTaskFunction < T extends TaskFunction < any , any [ ] > > =
15
+ Task < TaskFunctionReturnType < T > , TaskFunctionArgs < T > > ;
16
+
17
+ export type TaskInstanceForTaskFunction < T extends TaskFunction < any , any [ ] > > =
18
+ TaskInstance < TaskFunctionReturnType < T > > ;
19
+
14
20
export interface EncapsulatedTaskDescriptor < T , Args extends any [ ] > {
15
21
perform ( ...args : Args ) : TaskGenerator < T > ;
16
22
}
@@ -21,16 +27,19 @@ export type EncapsulatedTaskDescriptorArgs<T extends EncapsulatedTaskDescriptor<
21
27
export type EncapsulatedTaskDescriptorReturnType < T extends EncapsulatedTaskDescriptor < any , any [ ] > > =
22
28
T extends { perform ( ...args : any [ ] ) : TaskGenerator < infer R > } ? R : unknown ;
23
29
24
- /**
25
- * The `Task` object lives on a host Ember object (e.g.
26
- * a Component, Route, or Controller). You call the
27
- * {@linkcode Task#perform .perform()} method on this object
28
- * to create run individual {@linkcode TaskInstance}s,
29
- * and at any point, you can call the {@linkcode Task#cancelAll .cancelAll()}
30
- * method on this object to cancel all running or enqueued
31
- * {@linkcode TaskInstance}s.
32
- */
33
- export interface Task < T , Args extends any [ ] > extends EmberObject {
30
+ export type EncapsulatedTaskState < T extends object > = Omit < T , 'perform' | keyof TaskInstance < any > > ;
31
+
32
+ export type TaskForEncapsulatedTaskDescriptor < T extends EncapsulatedTaskDescriptor < any , any [ ] > > =
33
+ EncapsulatedTask <
34
+ EncapsulatedTaskDescriptorReturnType < T > ,
35
+ EncapsulatedTaskDescriptorArgs < T > ,
36
+ EncapsulatedTaskState < T >
37
+ > ;
38
+
39
+ export type TaskInstanceForEncapsulatedTaskDescriptor < T extends EncapsulatedTaskDescriptor < any , any [ ] > > =
40
+ EncapsulatedTaskInstance < EncapsulatedTaskDescriptorReturnType < T > , EncapsulatedTaskState < T > > ;
41
+
42
+ interface AbstractTask < Args extends any [ ] , T extends TaskInstance < any > > extends EmberObject {
34
43
/**
35
44
* `true` if any current task instances are running.
36
45
*/
@@ -54,42 +63,42 @@ export interface Task<T, Args extends any[]> extends EmberObject {
54
63
/**
55
64
* The most recently started task instance.
56
65
*/
57
- readonly last : TaskInstance < T > | null ;
66
+ readonly last : T | null ;
58
67
59
68
/**
60
69
* The most recent task instance that is currently running.
61
70
*/
62
- readonly lastRunning : TaskInstance < T > | null ;
71
+ readonly lastRunning : T | null ;
63
72
64
73
/**
65
74
* The most recently performed task instance.
66
75
*/
67
- readonly lastPerformed : TaskInstance < T > | null ;
76
+ readonly lastPerformed : T | null ;
68
77
69
78
/**
70
79
* The most recent task instance that succeeded.
71
80
*/
72
- readonly lastSuccessful : TaskInstance < T > | null ;
81
+ readonly lastSuccessful : T | null ;
73
82
74
83
/**
75
84
* The most recently completed task instance.
76
85
*/
77
- readonly lastComplete : TaskInstance < T > | null ;
86
+ readonly lastComplete : T | null ;
78
87
79
88
/**
80
89
* The most recent task instance that errored.
81
90
*/
82
- readonly lastErrored : TaskInstance < T > | null ;
91
+ readonly lastErrored : T | null ;
83
92
84
93
/**
85
94
* The most recently canceled task instance.
86
95
*/
87
- readonly lastCanceled : TaskInstance < T > | null ;
96
+ readonly lastCanceled : T | null ;
88
97
89
98
/**
90
99
* The most recent task instance that is incomplete.
91
100
*/
92
- readonly lastIncomplete : TaskInstance < T > | null ;
101
+ readonly lastIncomplete : T | null ;
93
102
94
103
/**
95
104
* The number of times this task has been performed.
@@ -120,9 +129,24 @@ export interface Task<T, Args extends any[]> extends EmberObject {
120
129
*
121
130
* @param args Arguments to pass to the task function.
122
131
*/
123
- perform ( ...args : Args ) : TaskInstance < T > ;
132
+ perform ( ...args : Args ) : T ;
124
133
}
125
134
135
+ /**
136
+ * The `Task` object lives on a host Ember object (e.g.
137
+ * a Component, Route, or Controller). You call the
138
+ * {@linkcode Task#perform .perform()} method on this object
139
+ * to create run individual {@linkcode TaskInstance}s,
140
+ * and at any point, you can call the {@linkcode Task#cancelAll .cancelAll()}
141
+ * method on this object to cancel all running or enqueued
142
+ * {@linkcode TaskInstance}s.
143
+ */
144
+ export interface Task < T , Args extends any [ ] >
145
+ extends AbstractTask < Args , TaskInstance < T > > { }
146
+
147
+ export interface EncapsulatedTask < T , Args extends any [ ] , State extends object >
148
+ extends AbstractTask < Args , EncapsulatedTaskInstance < T , State > > { }
149
+
126
150
/**
127
151
* "Task Groups" provide a means for applying
128
152
* task modifiers to groups of tasks. Once a {@linkcode Task} is declared
@@ -333,16 +357,9 @@ export interface TaskInstance<T> extends Promise<T>, EmberObject {
333
357
finally ( onfinally ?: ( ( ) => void ) | null ) : Promise < T > ;
334
358
}
335
359
336
- /**
337
- * A {@link TaskProperty} is the Computed Property-like object returned
338
- * from the {@linkcode task} function. You can call Task Modifier methods
339
- * on this object to configure the behavior of the {@link Task}.
340
- *
341
- * See [Managing Task Concurrency](/#/docs/task-concurrency) for an
342
- * overview of all the different task modifiers you can use and how
343
- * they impact automatic cancelation / enqueueing of task instances.
344
- */
345
- export interface TaskProperty < T , Args extends any [ ] > extends ComputedProperty < Task < T , Args > > {
360
+ type EncapsulatedTaskInstance < T , State extends object > = TaskInstance < T > & EncapsulatedTaskState < State > ;
361
+
362
+ interface AbstractTaskProperty < T extends Task < any , any [ ] > > extends ComputedProperty < T > {
346
363
volatile : never ;
347
364
readOnly : never ;
348
365
property : never ;
@@ -483,6 +500,21 @@ export interface TaskProperty<T, Args extends any[]> extends ComputedProperty<Ta
483
500
debug ( ) : this;
484
501
}
485
502
503
+ /**
504
+ * A {@link TaskProperty} is the Computed Property-like object returned
505
+ * from the {@linkcode task} function. You can call Task Modifier methods
506
+ * on this object to configure the behavior of the {@link Task}.
507
+ *
508
+ * See [Managing Task Concurrency](/#/docs/task-concurrency) for an
509
+ * overview of all the different task modifiers you can use and how
510
+ * they impact automatic cancelation / enqueueing of task instances.
511
+ */
512
+ export interface TaskProperty < T , Args extends any [ ] >
513
+ extends AbstractTaskProperty < Task < T , Args > > { }
514
+
515
+ export interface EncapsulatedTaskProperty < T , Args extends any [ ] , State extends object >
516
+ extends AbstractTaskProperty < EncapsulatedTask < T , Args , State > > { }
517
+
486
518
export interface TaskGroupProperty < T > extends ComputedProperty < TaskGroup < T > > {
487
519
volatile : never ;
488
520
readOnly : never ;
@@ -645,7 +677,11 @@ type Settled<T> = Settlement<Resolved<T>>;
645
677
export function task < T extends TaskFunction < any , any [ ] > > ( taskFn : T ) :
646
678
TaskProperty < TaskFunctionReturnType < T > , TaskFunctionArgs < T > > ;
647
679
export function task < T extends EncapsulatedTaskDescriptor < any , any [ ] > > ( taskFn : T ) :
648
- TaskProperty < EncapsulatedTaskDescriptorReturnType < T > , EncapsulatedTaskDescriptorArgs < T > > ;
680
+ EncapsulatedTaskProperty <
681
+ EncapsulatedTaskDescriptorReturnType < T > ,
682
+ EncapsulatedTaskDescriptorArgs < T > ,
683
+ EncapsulatedTaskState < T >
684
+ > ;
649
685
650
686
/**
651
687
* "Task Groups" provide a means for applying
0 commit comments