ES Proposal spec-compliant shim for Promise.allKeyed. Invoke its "shim" method to shim Promise.allKeyed if it is unavailable or noncompliant. Note: a global Promise must already exist: the es6-shim is recommended.
This package implements the es-shim API interface. It works in an ES3-supported environment that has Promise available globally, and complies with the proposed spec.
Promise.allKeyed is like Promise.all, but for a dictionary (a plain object) rather than an iterable: it awaits every enumerable own property value, and fulfills with a null-prototype object of the same keys mapped to their resolved values. As with Promise.all, it rejects as soon as any input rejects.
Most common usage:
var assert = require('assert');
var allKeyed = require('promise.allkeyed');
allKeyed({
shape: Promise.resolve('square'),
color: 'blue',
mass: Promise.resolve(42)
}).then(function (results) {
assert.equal(results.shape, 'square');
assert.equal(results.color, 'blue');
assert.equal(results.mass, 42);
});
require('promise.allkeyed/shim')(); // will be a no-op if not needed
Promise.allKeyed({
a: Promise.resolve(1),
b: 2
}).then(function (results) {
assert.equal(results.a, 1);
assert.equal(results.b, 2);
});The polyfill, implementation, and shim methods are available as separate entry points, per the es-shim API:
var getPolyfill = require('promise.allkeyed/polyfill');
var implementation = require('promise.allkeyed/implementation');
var shim = require('promise.allkeyed/shim');Simply clone the repo, npm install, and run npm test
