1
2
3/**
4 * This function transforms a JS object `ObjMap<Promise<T>>` into
5 * a `Promise<ObjMap<T>>`
6 *
7 * This is akin to bluebird's `Promise.props`, but implemented only using
8 * `Promise.all` so it will work with any implementation of ES6 promises.
9 */
10export default function promiseForObject(object) {
11  var keys = Object.keys(object);
12  var valuesAndPromises = keys.map(function (name) {
13    return object[name];
14  });
15  return Promise.all(valuesAndPromises).then(function (values) {
16    return values.reduce(function (resolvedObject, value, i) {
17      resolvedObject[keys[i]] = value;
18      return resolvedObject;
19    }, Object.create(null));
20  });
21} /**
22   * Copyright (c) 2015-present, Facebook, Inc.
23   *
24   * This source code is licensed under the MIT license found in the
25   * LICENSE file in the root directory of this source tree.
26   *
27   *  strict
28   */