Comparing version 4.4.0 to 4.4.1
@@ -177,8 +177,13 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
value: function execute(value) { | ||
var _this2 = this; | ||
if (this.condition(value)) { | ||
var actionResult = this.action(value); | ||
return _bluebird2.default.reduce(this.branches, function (result, branch) { | ||
return result !== null ? _bluebird2.default.resolve(result) : branch.execute(actionResult); | ||
}, null).then(function (childBranchResult) { | ||
return childBranchResult || actionResult; | ||
return _bluebird2.default.resolve().then(function () { | ||
return _this2.action(value); | ||
}).then(function (actionResult) { | ||
return _bluebird2.default.reduce(_this2.branches, function (result, branch) { | ||
return result !== null ? _bluebird2.default.resolve(result) : branch.execute(actionResult); | ||
}, null).then(function (childBranchResult) { | ||
return childBranchResult || actionResult; | ||
}); | ||
}); | ||
@@ -185,0 +190,0 @@ } |
{ | ||
"name": "horpyna", | ||
"version": "4.4.0", | ||
"version": "4.4.1", | ||
"description": "utility to manage async processes", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -48,8 +48,11 @@ import { convertToBranches, convertToBranch } from "./convertToBranches"; | ||
if (this.condition(value)) { | ||
const actionResult = this.action(value); | ||
return Promise.reduce( | ||
this.branches, | ||
(result, branch) => (result !== null ? Promise.resolve(result) : branch.execute(actionResult)), | ||
null | ||
).then(childBranchResult => childBranchResult || actionResult); | ||
return Promise.resolve() | ||
.then(() => this.action(value)) | ||
.then(actionResult => | ||
Promise.reduce( | ||
this.branches, | ||
(result, branch) => (result !== null ? Promise.resolve(result) : branch.execute(actionResult)), | ||
null | ||
).then(childBranchResult => childBranchResult || actionResult) | ||
); | ||
} | ||
@@ -56,0 +59,0 @@ return Promise.resolve(null); |
/* eslint-disable no-unused-vars, no-new */ | ||
import Branch from "./Branch"; | ||
import Promise from "bluebird"; | ||
@@ -43,2 +44,13 @@ describe("Branch", () => { | ||
}); | ||
describe("when branch action returns promise", () => { | ||
it("should return value", () => { | ||
const mainBranch = new Branch({ | ||
name: "mainBranch", | ||
action: value => Promise.resolve(value + 1), | ||
branches: [{ name: "otherSubBranch", action: value => value + 1 }] | ||
}); | ||
return mainBranch.execute(10).then(value => expect(value).to.be.equal(12)); | ||
}); | ||
}); | ||
describe("when conditions not met", () => { | ||
@@ -45,0 +57,0 @@ describe("when no child branches", () => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
93634
735