extends-promise
Advanced tools
Comparing version 1.3.0 to 1.4.0
10
index.js
@@ -117,2 +117,12 @@ "use strict"; | ||
static props(o) { | ||
const keys = Object.keys(o); | ||
return P | ||
.map(keys, k => o[k]) | ||
.then(res => res.reduce((y, x, i) => Object.assign(y, { | ||
[keys[i]] : x | ||
}), {})); | ||
} | ||
static promisify(fn, ctx) { | ||
@@ -119,0 +129,0 @@ return function promisifedMethod() { |
{ | ||
"name": "extends-promise", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Micro-library that extends native promises", | ||
@@ -33,9 +33,9 @@ "main": "index.js", | ||
"eslint-config-airbnb-base": "^3.0.1", | ||
"eslint-plugin-import": "^1.8.0", | ||
"eslint-plugin-import": "^1.9.0", | ||
"gulp": "^3.9.1", | ||
"gulp-coveralls": "^0.1.4", | ||
"gulp-eslint": "^2.0.0", | ||
"gulp-istanbul": "^0.10.4", | ||
"gulp-istanbul": "^1.0.0", | ||
"gulp-mocha": "^2.2.0" | ||
} | ||
} |
@@ -20,2 +20,3 @@ [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url] | ||
- [`defer(Function fn)`](#deferfunction-fn) | ||
- [`props(Object obj)`](#propsobject-obj) | ||
- [`extend(Promise)`](#extendpromise) | ||
@@ -150,2 +151,31 @@ * [Instance Methods](#instance-methods) | ||
#### `props(Object obj)` | ||
Accepts an object and waits for all promise values to resolve before returning. Returns | ||
a new object with values from the resolved promises. | ||
```js | ||
const P = require("extends-promise"); | ||
P | ||
.props({ | ||
x : P.delay(100, 'a'), | ||
y : P.delay(50, 'b'), | ||
z : 'c' | ||
}) | ||
.then(res => console.log(res.x)); | ||
``` | ||
This method can be especially helpful when combined with destructuring as a way of returning | ||
named tuples. | ||
```js | ||
P | ||
.props({ | ||
x : P.delay(100, 'a'), | ||
y : 'b' | ||
}) | ||
.then(({ x, y }) => console.log(`x: ${x}, y: ${y}`)); | ||
``` | ||
#### `extend(Promise)` | ||
@@ -152,0 +182,0 @@ |
@@ -87,3 +87,3 @@ "use strict"; | ||
describe(".tap", () => { | ||
it(".tap: should be able to call then without affecting chain", () => { | ||
it("should be able to call then without affecting chain", () => { | ||
return P | ||
@@ -95,3 +95,3 @@ .resolve(1) | ||
it(".tap: should wait for returned promise to resolve", () => { | ||
it("should wait for returned promise to resolve", () => { | ||
let waited = false; | ||
@@ -110,2 +110,28 @@ | ||
}); | ||
describe(".props", () => { | ||
it("should wait for promise values to reolve", () => { | ||
return P | ||
.props({ | ||
x : P.delay(1, 'a'), | ||
y : P.delay(5, 'b') | ||
}) | ||
.then(res => assert.deepEqual(res, { | ||
x : 'a', | ||
y : 'b' | ||
})); | ||
}); | ||
it("should allow non-promise keys", () => { | ||
return P | ||
.props({ | ||
x : P.delay(1, 'a'), | ||
y : 'b' | ||
}) | ||
.then(res => assert.deepEqual(res, { | ||
x : 'a', | ||
y : 'b' | ||
})); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34070
781
372