@@ -27,6 +27,11 @@ const removeElement = (arr, element) => {
27
27
/**
28
28
* @typedef {function } UseAsyncEffectCancelFn
29
29
* @param {string } [reason]
30
+ * @property {Boolean } done
31
+ * @property {* } result
32
+ * @property {* } error
33
+ * @property {boolean } canceled
34
+ * @property {UseAsyncEffectCancelFn } cancel
30
35
* @property {PauseFn } pause
31
36
* @property {ResumeFn } resume
32
37
* returns {boolean}
@@ -46,15 +51,15 @@ const removeElement = (arr, element) => {
46
51
47
52
/**
48
53
* AsyncEffect hook to define cancellable effects
49
- * @param {GeneratorFunction } generator
54
+ * @param {GeneratorFunction } generatorFn
50
55
* @param {object } [options]
51
56
* @param {deps } [options.deps= []]
52
57
* @param {boolean } [options.skipFirst= false]
53
58
* @param {boolean } [options.states= false]
54
59
* @param {boolean } [options.once= false]
55
60
* @returns {UseAsyncEffectCancelFn }
56
61
*/
57
- const useAsyncEffect = ( generator , options ) => {
62
+ const useAsyncEffect = ( generatorFn , options ) => {
58
63
let { current} = useRef ( { } ) ;
59
64
60
65
let {
@@ -74,7 +79,7 @@ const useAsyncEffect = (generator, options) => {
74
79
75
80
const [ state , setState ] = states ? useAsyncDeepState ( initialState , { watch : false } ) : [ ] ;
76
81
77
- if ( ! isGeneratorFn ( generator ) ) {
82
+ if ( ! isGeneratorFn ( generatorFn ) ) {
78
83
throw TypeError ( 'useAsyncEffect requires a generator as the first argument' ) ;
79
84
}
80
85
@@ -120,7 +125,7 @@ const useAsyncEffect = (generator, options) => {
120
125
121
126
states && setState ( initialState ) ;
122
127
123
- let promise = current . promise = CPromise . run ( generator , { resolveSignatures : true , scopeArg : true } )
128
+ let promise = current . promise = CPromise . run ( generatorFn , { resolveSignatures : true , scopeArg : true } )
124
129
. then ( result => {
125
130
126
131
current . done = true ;
@@ -186,6 +191,7 @@ const useAsyncEffect = (generator, options) => {
186
191
cancel . error = state . error ;
187
192
cancel . canceled = state . canceled ;
188
193
cancel . paused = state . paused ;
194
+ cancel . cancel = cancel ;
189
195
}
190
196
191
197
return cancel ;
@@ -270,7 +276,7 @@ const asyncEffectFactory= (options) => {
270
276
271
277
/**
272
278
* useAsyncCallback hook for defining cancellable async routines
273
- * @param {GeneratorFunction } generator
279
+ * @param {GeneratorFunction } generatorFn
274
280
* @param {object|array } [options]
275
281
* @param {array } [options.deps= []]
276
282
* @param {boolean } [options.combine= false]
@@ -282,7 +288,7 @@ const asyncEffectFactory= (options) => {
282
288
* @param {boolean } [options.catchErrors= true]
283
289
* @returns {UseAsyncCallbackDecoratedFn }
284
290
*/
285
- const useAsyncCallback = ( generator , options ) => {
291
+ const useAsyncCallback = ( generatorFn , options ) => {
286
292
const current = useFactory ( asyncEffectFactory , [ options ] ) ;
287
293
288
294
let {
@@ -327,7 +333,7 @@ const useAsyncCallback = (generator, options) => {
327
333
}
328
334
}
329
335
330
- const resolveGenerator = ( ) => CPromise . run ( generator , { args, resolveSignatures : true , scopeArg} ) ;
336
+ const resolveGenerator = ( ) => CPromise . run ( generatorFn , { args, resolveSignatures : true , scopeArg} ) ;
331
337
332
338
cancelPrevious && ! combine && cancel ( E_REASON_RESTART ) ;
333
339
0 commit comments