Comparing version 1.3.1 to 1.4.0
@@ -104,2 +104,6 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var _createGetBranch = __webpack_require__(10); | ||
var _createGetBranch2 = _interopRequireDefault(_createGetBranch); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -113,2 +117,3 @@ | ||
setValue.setBranch = (0, _createSetBranch2.default)(options, debug); | ||
setValue.getBranch = (0, _createGetBranch2.default)(options, debug); | ||
return setValue; | ||
@@ -318,2 +323,31 @@ } | ||
/***/ }), | ||
/* 10 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = createGetBranch; | ||
function createGetBranch(options, debug) { | ||
debug("create 'getBranch' function"); | ||
return function (branchName) { | ||
var deepSearch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
debug("call 'getBranch' function with name", branchName); | ||
var directChildBranch = options.branches[branchName]; | ||
if (directChildBranch) { | ||
return directChildBranch; | ||
} | ||
if (deepSearch) { | ||
return Object.keys(options.branches).reduce(function (branch, name) { | ||
return branch || options.branches[name].getBranch(branchName, true); | ||
}, undefined); | ||
} | ||
}; | ||
} | ||
/***/ }) | ||
@@ -320,0 +354,0 @@ /******/ ]); |
{ | ||
"name": "horpyna", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "utility to manage async processes", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -66,2 +66,100 @@ /* eslint-disable no-unused-vars */ | ||
}); | ||
describe("when searching only direct children", () => { | ||
describe("when direct child with searched name doesn't exist", () => { | ||
it("should return undefined", () => { | ||
const deepChildBranch = Horpyna({ | ||
condition: () => true, | ||
action: value => value | ||
}); | ||
const directChildBranch = Horpyna({ | ||
condition: () => true, | ||
action: value => value, | ||
branches: { | ||
searchBranchName: deepChildBranch | ||
} | ||
}); | ||
const mainBranch = Horpyna({ | ||
condition: () => true, | ||
action: value => value, | ||
branches: { | ||
differentBranchName: directChildBranch | ||
} | ||
}); | ||
expect(mainBranch.getBranch("searchBranchName", false)).to.be.undefined(); | ||
}); | ||
}); | ||
describe("when direct child with searched name exist", () => { | ||
it("should return direct child", () => { | ||
const deepChildBranch = Horpyna({ | ||
condition: () => true, | ||
action: value => value | ||
}); | ||
const directChildBranch = Horpyna({ | ||
condition: () => true, | ||
action: value => value, | ||
branches: { | ||
differentBranchName: deepChildBranch | ||
} | ||
}); | ||
const mainBranch = Horpyna({ | ||
condition: () => true, | ||
action: value => value, | ||
branches: { | ||
searchBranchName: directChildBranch | ||
} | ||
}); | ||
expect(mainBranch.getBranch("searchBranchName", false)).to.be.equal(directChildBranch); | ||
}); | ||
}); | ||
}); | ||
describe("when deep searching", () => { | ||
describe("when child with searched name doesn't exist", () => { | ||
it("should return undefined", () => { | ||
const deepChildBranch = Horpyna({ | ||
condition: () => true, | ||
action: value => value | ||
}); | ||
const directChildBranch = Horpyna({ | ||
condition: () => true, | ||
action: value => value, | ||
branches: { | ||
alsoWrongBranchName: deepChildBranch | ||
} | ||
}); | ||
const mainBranch = Horpyna({ | ||
condition: () => true, | ||
action: value => value, | ||
branches: { | ||
differentBranchName: directChildBranch | ||
} | ||
}); | ||
expect(mainBranch.getBranch("searchBranchName")).to.be.undefined(); | ||
}); | ||
}); | ||
describe("when child with searched name exist", () => { | ||
it("should return child branch", () => { | ||
const deepChildBranch = Horpyna({ | ||
condition: () => true, | ||
action: value => value | ||
}); | ||
const directChildBranch = Horpyna({ | ||
condition: () => true, | ||
action: value => value, | ||
branches: { | ||
searchBranchName: deepChildBranch | ||
} | ||
}); | ||
const mainBranch = Horpyna({ | ||
condition: () => true, | ||
action: value => value, | ||
branches: { | ||
differentBranchName: directChildBranch | ||
} | ||
}); | ||
expect(mainBranch.getBranch("searchBranchName")).to.be.equal(deepChildBranch); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -5,2 +5,3 @@ import createSetValue from "./actions/createSetValue"; | ||
import createSetBranch from "./actions/createSetBranch"; | ||
import createGetBranch from "./actions/createGetBranch"; | ||
export default function response(options, debug) { | ||
@@ -12,3 +13,4 @@ options = Object.assign({}, options); | ||
setValue.setBranch = createSetBranch(options, debug); | ||
setValue.getBranch = createGetBranch(options, debug); | ||
return setValue; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
75414
29
554