Skip to content

Commit

Permalink
Make utils.resolveProperties preserve object parameter order.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jul 27, 2019
1 parent 28eb38e commit 74dbc28
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions packages/properties/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,27 @@ export function getStatic<T>(ctor: any, key: string): T {
return null;
}

type Result = { key: string, value: any};
export function resolveProperties(object: any): Promise<any> {
let result: any = {};

let promises: Array<Promise<void>> = [];
Object.keys(object).forEach((key) => {
let promises: Array<Promise<Result>> = Object.keys(object).map((key) => {
let value = object[key];
if (value instanceof Promise) {
promises.push(
value.then((value) => {
result[key] = value;
return null;
})
);
} else {
result[key] = value;

if (!(value instanceof Promise)) {
return Promise.resolve({ key: key, value: value });
}

return value.then((value) => {
return { key: key, value: value };
});
});

return Promise.all(promises).then(() => {
return result;
return Promise.all(promises).then((results) => {
let result: any = { };
return results.reduce((accum, result) => {
accum[result.key] = result.value;
return accum;
}, result);
});
}

Expand Down

0 comments on commit 74dbc28

Please sign in to comment.