Muthu Kumar
7 years ago
commit
a998da9810
6 changed files with 69 additions and 0 deletions
@ -0,0 +1 @@ |
|||||
|
node_modules |
@ -0,0 +1,14 @@ |
|||||
|
{ |
||||
|
// Use IntelliSense to learn about possible attributes. |
||||
|
// Hover to view descriptions of existing attributes. |
||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
||||
|
"version": "0.2.0", |
||||
|
"configurations": [ |
||||
|
{ |
||||
|
"type": "node", |
||||
|
"request": "launch", |
||||
|
"name": "Launch Program", |
||||
|
"program": "${workspaceFolder}/test.js" |
||||
|
} |
||||
|
] |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
module.exports = require('../index.js'); |
@ -0,0 +1,5 @@ |
|||||
|
{ |
||||
|
"name": "@codefeathers/promise.object", |
||||
|
"version": "0.0.1", |
||||
|
"lockfileVersion": 1 |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
{ |
||||
|
"name": "@codefeathers/promise.object", |
||||
|
"version": "0.0.1", |
||||
|
"description": "Deep resolving promises in objects.", |
||||
|
"main": "es6/index.js", |
||||
|
"scripts": { |
||||
|
"test": "echo \"Error: no test specified\" && exit 1" |
||||
|
}, |
||||
|
"keywords": [], |
||||
|
"author": "Muthu Kumar <@MKRhere> (https://mkr.pw)", |
||||
|
"contributors": [ |
||||
|
"Thomas Rory Gummerson <@TRGWII> (https://rory.no)" |
||||
|
], |
||||
|
"license": "MIT" |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
Promise.object = require('./es6'); |
||||
|
const assert = require('assert'); |
||||
|
|
||||
|
const linked = { |
||||
|
foo: Promise.resolve(1), |
||||
|
bar: { |
||||
|
foobar: Promise.resolve(2) |
||||
|
}, |
||||
|
baz: [1, "two", Promise.resolve(3)], |
||||
|
ok: "four" |
||||
|
} |
||||
|
|
||||
|
linked.linked = linked; |
||||
|
|
||||
|
Promise.object(linked).then(x => { |
||||
|
console.log(x); |
||||
|
assert(x.foo === 1); |
||||
|
assert(x.bar.foobar === 2); |
||||
|
assert(x.baz[0] === 1 && x.baz[1] === "two"); |
||||
|
assert(Array.isArray(x.baz) && x.baz[2] === 3); |
||||
|
assert(x.linked === x); |
||||
|
}); |
||||
|
|
||||
|
Promise.object( |
||||
|
Promise.resolve({ |
||||
|
foo: Promise.resolve({ |
||||
|
bar: Promise.resolve(4) |
||||
|
}) |
||||
|
}) |
||||
|
).then(x => { |
||||
|
console.log(x) |
||||
|
assert(x.foo.bar === 4); |
||||
|
}); |
Loading…
Reference in new issue