Comparing version 2.0.0 to 3.0.0
{ | ||
"name": "pdi", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Minimal Promise based dependency injection framework", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -89,4 +89,4 @@ # PDI - Minimal Promise based Dependency Injection framework | ||
flow | ||
.start(["result"]) | ||
.then(result => res.send(result)) | ||
.start() | ||
.then(({ result }) => res.send(result)) | ||
.catch(err => res.sendStatus(500)) | ||
@@ -93,0 +93,0 @@ ``` |
@@ -14,5 +14,2 @@ const Promise = require("bluebird") | ||
pick, | ||
flip, | ||
apply, | ||
prop, | ||
compose, | ||
@@ -125,3 +122,3 @@ merge, | ||
} | ||
function start(deps, fn) { | ||
function start() { | ||
if (activated) { | ||
@@ -137,9 +134,3 @@ throw new Error("DI already activated") | ||
activated = true | ||
let result = true | ||
if (deps && fn) { | ||
debug(`Running start function with ${deps.join(", ")}`) | ||
result = apply(fn, map(flip(prop)(modules), deps)) | ||
} | ||
return Promise.resolve(result) | ||
return Object.assign({}, modules) | ||
}) | ||
@@ -146,0 +137,0 @@ } |
@@ -123,2 +123,37 @@ /* eslint max-nested-callbacks: 0 */ | ||
it("resolves with all dependencies", () => { | ||
const fn1 = () => "foo" | ||
const fn2 = () => "bar" | ||
pdi.add("1", ["2"], fn1) | ||
pdi.add("2", fn2) | ||
return pdi.start().then(result => { | ||
equal(result["1"], "foo") | ||
equal(result["2"], "bar") | ||
}) | ||
}) | ||
it("rejects when dependency throws", () => { | ||
const fn1 = () => { | ||
throw new Error("error in dep") | ||
} | ||
const fn2 = () => "bar" | ||
pdi.add("1", ["2"], fn1) | ||
pdi.add("2", fn2) | ||
return pdi.start().catch(err => { | ||
ok(err) | ||
equal(err.message, "error in dep") | ||
}) | ||
}) | ||
it("rejects when dependency rejects", () => { | ||
const fn1 = () => Promise.reject(new Error("error in dep")) | ||
const fn2 = () => "bar" | ||
pdi.add("1", ["2"], fn1) | ||
pdi.add("2", fn2) | ||
return pdi.start().catch(err => { | ||
ok(err) | ||
equal(err.message, "error in dep") | ||
}) | ||
}) | ||
it("calls each registered function with deps", () => { | ||
@@ -125,0 +160,0 @@ const foo = Math.random() |
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
49801
311