File tree Expand file tree Collapse file tree 1 file changed +15
-14
lines changed
packages/properties/src.ts Expand file tree Collapse file tree 1 file changed +15
-14
lines changed Original file line number Diff line number Diff line change @@ -20,26 +20,27 @@ export function getStatic<T>(ctor: any, key: string): T {
20
20
return null ;
21
21
}
22
22
23
+ type Result = { key : string , value : any } ;
23
24
export function resolveProperties ( object : any ) : Promise < any > {
24
- let result : any = { } ;
25
25
26
- let promises : Array < Promise < void > > = [ ] ;
27
- Object . keys ( object ) . forEach ( ( key ) => {
26
+ let promises : Array < Promise < Result > > = Object . keys ( object ) . map ( ( key ) => {
28
27
let value = object [ key ] ;
29
- if ( value instanceof Promise ) {
30
- promises . push (
31
- value . then ( ( value ) => {
32
- result [ key ] = value ;
33
- return null ;
34
- } )
35
- ) ;
36
- } else {
37
- result [ key ] = value ;
28
+
29
+ if ( ! ( value instanceof Promise ) ) {
30
+ return Promise . resolve ( { key : key , value : value } ) ;
38
31
}
32
+
33
+ return value . then ( ( value ) => {
34
+ return { key : key , value : value } ;
35
+ } ) ;
39
36
} ) ;
40
37
41
- return Promise . all ( promises ) . then ( ( ) => {
42
- return result ;
38
+ return Promise . all ( promises ) . then ( ( results ) => {
39
+ let result : any = { } ;
40
+ return results . reduce ( ( accum , result ) => {
41
+ accum [ result . key ] = result . value ;
42
+ return accum ;
43
+ } , result ) ;
43
44
} ) ;
44
45
}
45
46
You can’t perform that action at this time.
0 commit comments