File tree 3 files changed +17
-0
lines changed
3 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 13
13
* Apply arguments to a function.
14
14
*/
15
15
const funcApply = ( func , args ) => func ( ...args )
16
+
17
+ module . exports = funcApply
Original file line number Diff line number Diff line change @@ -3837,6 +3837,12 @@ eq(
3837
3837
assert . strictEqual ( thunkAdd212 . length , 0 )
3838
3838
assert . strictEqual ( thunkAdd212 ( ) , 3 )
3839
3839
} )
3840
+
3841
+ const asyncThunkAdd212 = thunkify ( add2 , Promise . resolve ( 1 ) , 2 )
3842
+ it ( 'creates a thunk that resolves any promise arguments' , async ( ) => {
3843
+ assert . strictEqual ( asyncThunkAdd212 . length , 0 )
3844
+ assert . strictEqual ( await asyncThunkAdd212 ( ) , 3 )
3845
+ } )
3840
3846
} )
3841
3847
3842
3848
describe ( 'always' , ( ) => {
Original file line number Diff line number Diff line change
1
+ const areAnyValuesPromises = require ( './_internal/areAnyValuesPromises' )
2
+ const promiseAll = require ( './_internal/promiseAll' )
3
+ const curry2 = require ( './_internal/curry2' )
4
+ const __ = require ( './_internal/placeholder' )
5
+ const funcApply = require ( './_internal/funcApply' )
6
+
1
7
/**
2
8
* @name thunkify
3
9
*
18
24
* ```
19
25
*/
20
26
const thunkify = ( func , ...args ) => function thunk ( ) {
27
+ if ( areAnyValuesPromises ( args ) ) {
28
+ return promiseAll ( args ) . then ( curry2 ( funcApply , func , __ ) )
29
+ }
21
30
return func ( ...args )
22
31
}
23
32
You can’t perform that action at this time.
0 commit comments