📤 Deep resolve promises in objects.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Muthu Kumar abf53be3fd
[docs] Added credits
6 years ago
.circleci [ci] 6 years ago
.vscode [init] 6 years ago
es5 [build] Added build script 6 years ago
es6 [init] 6 years ago
spec [build] Added build script 6 years ago
.gitignore [init] 6 years ago
README.md [docs] Added credits 6 years ago
build.sh [build] Added build script 6 years ago
index.js [Promise.object] Resolves all promises in nested, cyclic objects 6 years ago
package-lock.json [ci] 6 years ago
package.json [build] Added build script 6 years ago

README.md

📤 Promise.object

A Promise.object implementation that deep traverses objects and resolves any Promises.

Installation

npm install --save @codefeathers/promise.object

Usage

Promise.object(<Object>).then(...)

Note that importing this library does not pollute the Promise namespace. You should assign it to Promise.object yourself (or whatever you please). It does not interfere with native Promises, or your own Promises A+ compatible library such as Bluebird. It however uses Promises, so if you need to polyfill this is your chance.

Example

Promise.object = require('@codefeathers/promise.object');
const { log } = console;

Promise.object({
	foo: Promise.resolve(5),
	bar: {
		baz: Promise.resolve([ 1, 2, 3 ])
	}
}).then(log);

//-> { foo: 5, bar: { baz: [ 1, 2, 3 ] } }

We need to go deeper!

Promise.object = require('@codefeathers/promise.object');
const { log } = console;

Promise.object(
	Promise.resolve({
		foo: Promise.resolve({
			bar: Promise.resolve(5)
		})
	})
).then(log);

//-> { foo: { bar: 5 } } 

Credits

The original idea and challenge was all @TRGWII.