Comparing version 0.1.0 to 0.1.1
@@ -87,2 +87,6 @@ require("source-map-support").install(); | ||
var _errors = __webpack_require__(7); | ||
var ERROR = _interopRequireWildcard(_errors); | ||
var _statuses = __webpack_require__(5); | ||
@@ -108,4 +112,2 @@ | ||
this.componentFunction = componentFunction; | ||
} else { | ||
throw new Error(); | ||
} | ||
@@ -144,4 +146,8 @@ this.connectedChildrenComponents = []; | ||
value: function _runComponentFunction(request) { | ||
this.status = STATUS.PROCESS; | ||
this.componentFunction(request, this._getResponseObject()); | ||
if (typeof this.componentFunction === "function") { | ||
this.status = STATUS.PROCESS; | ||
this.componentFunction(request, this._getResponseObject()); | ||
} else { | ||
throw new Error(ERROR.NO_COMPONENT_FUNCTION); | ||
} | ||
} | ||
@@ -157,6 +163,4 @@ | ||
value: function _onParentReady() { | ||
if (this.rootComponent.status === STATUS.PROCESS) { | ||
if (Relation.hasComponentsStatus(this.connectedParentComponents, STATUS.DONE)) { | ||
this._runComponentFunction(this._getParentsOutput()); | ||
} | ||
if (Relation.hasComponentsStatus(this.connectedParentComponents, STATUS.DONE)) { | ||
this._runComponentFunction(this._getParentsOutput()); | ||
} | ||
@@ -193,13 +197,17 @@ } | ||
send: function send(output) { | ||
_this2.status = STATUS.DONE; | ||
_this2.output = output; | ||
_this2.connectedChildrenComponents.forEach(function (component) { | ||
return component._onParentReady(); | ||
}); | ||
_this2.rootComponent.onAnyDone(); | ||
if (_this2.rootComponent.status === STATUS.PROCESS) { | ||
_this2.status = STATUS.DONE; | ||
_this2.output = output; | ||
_this2.connectedChildrenComponents.forEach(function (component) { | ||
return component._onParentReady(); | ||
}); | ||
_this2.rootComponent.onAnyDone(); | ||
} | ||
}, | ||
finish: function finish(output) { | ||
_this2.status = STATUS.DONE; | ||
_this2.output = output; | ||
_this2.rootComponent.finish(output); | ||
if (_this2.rootComponent.status === STATUS.PROCESS) { | ||
_this2.status = STATUS.DONE; | ||
_this2.output = output; | ||
_this2.rootComponent.finish(output); | ||
} | ||
} | ||
@@ -395,3 +403,14 @@ }; | ||
/***/ }, | ||
/* 7 */ | ||
/***/ function(module, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var NO_COMPONENT_FUNCTION = exports.NO_COMPONENT_FUNCTION = "Component doesn't have function logic"; | ||
/***/ } | ||
/******/ ]))); |
{ | ||
"name": "horpyna", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "promised modules flow control core library", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
import Root from "./root"; | ||
import * as ERROR from "../constants/errors"; | ||
import * as STATUS from "../constants/statuses"; | ||
@@ -10,4 +11,2 @@ import * as Relation from "../helpers/Relation"; | ||
this.componentFunction = componentFunction; | ||
} else { | ||
throw new Error(); | ||
} | ||
@@ -35,4 +34,8 @@ this.connectedChildrenComponents = []; | ||
_runComponentFunction(request) { | ||
this.status = STATUS.PROCESS; | ||
this.componentFunction(request, this._getResponseObject()); | ||
if(typeof this.componentFunction === "function") { | ||
this.status = STATUS.PROCESS; | ||
this.componentFunction(request, this._getResponseObject()); | ||
} else { | ||
throw new Error(ERROR.NO_COMPONENT_FUNCTION); | ||
} | ||
} | ||
@@ -45,6 +48,4 @@ | ||
_onParentReady() { | ||
if(this.rootComponent.status === STATUS.PROCESS) { | ||
if (Relation.hasComponentsStatus(this.connectedParentComponents, STATUS.DONE)) { | ||
this._runComponentFunction(this._getParentsOutput()); | ||
} | ||
if (Relation.hasComponentsStatus(this.connectedParentComponents, STATUS.DONE)) { | ||
this._runComponentFunction(this._getParentsOutput()); | ||
} | ||
@@ -71,11 +72,15 @@ } | ||
send: output => { | ||
this.status = STATUS.DONE; | ||
this.output = output; | ||
this.connectedChildrenComponents.forEach(component => component._onParentReady()); | ||
this.rootComponent.onAnyDone(); | ||
if(this.rootComponent.status === STATUS.PROCESS) { | ||
this.status = STATUS.DONE; | ||
this.output = output; | ||
this.connectedChildrenComponents.forEach(component => component._onParentReady()); | ||
this.rootComponent.onAnyDone(); | ||
} | ||
}, | ||
finish: output => { | ||
this.status = STATUS.DONE; | ||
this.output = output; | ||
this.rootComponent.finish(output); | ||
if(this.rootComponent.status === STATUS.PROCESS) { | ||
this.status = STATUS.DONE; | ||
this.output = output; | ||
this.rootComponent.finish(output); | ||
} | ||
} | ||
@@ -82,0 +87,0 @@ }; |
@@ -17,14 +17,6 @@ import sinon from "sinon"; | ||
describe("Check basic single block", () => { | ||
it("should throw error if conponent doesnt have callback in constructor", (done) => { | ||
try { | ||
new Horpyna.Component(); | ||
} catch (e) { | ||
expect(e).to.be.deep.equal(new Error()); | ||
done(); | ||
} | ||
}); | ||
it("should resolve promise", (done) => { | ||
var spyComponent = sinon.spy(); | ||
var spyCustomFunc = sinon.spy(); | ||
it("should resolve promise when function logic is in constructor", (done) => { | ||
let spyComponent = sinon.spy(); | ||
let spyCustomFunc = sinon.spy(); | ||
let component = new Horpyna.Component((request, response) => { | ||
@@ -43,2 +35,33 @@ spyCustomFunc(); | ||
}); | ||
it("should resolve promise when function logic is as extend class method", (done) => { | ||
let spyComponent = sinon.spy(); | ||
let spyCustomFunc = sinon.spy(); | ||
let ExtendComponent = class extends Horpyna.Component { | ||
componentFunction(request, response) { | ||
spyCustomFunc(); | ||
response.finish(); | ||
} | ||
}; | ||
let component = new ExtendComponent(); | ||
let promise = component.run(); | ||
promise.then(() => { | ||
spyComponent(); | ||
expect(spyComponent.calledOnce).to.be.true; | ||
expect(spyCustomFunc.calledOnce).to.be.true; | ||
expect(spyCustomFunc.calledBefore(spyComponent)).to.be.true; | ||
done(); | ||
}); | ||
}); | ||
it("should throw error if component doesn't have function logic", (done) => { | ||
let component = new Horpyna.Component(); | ||
let promise = component.run(); | ||
promise.catch(e => { | ||
expect(e).to.be.deep.equal(new Error()); | ||
done(); | ||
}); | ||
}); | ||
it("should return value to child component", (done) => { | ||
@@ -61,6 +84,6 @@ const RESPONSE = "1234456564"; | ||
it("should return promise in run method and resolve it", (done) => { | ||
var spyA = sinon.spy(); | ||
var spyB = sinon.spy(); | ||
var spyC = sinon.spy(); | ||
var spyComponent = sinon.spy(); | ||
let spyA = sinon.spy(); | ||
let spyB = sinon.spy(); | ||
let spyC = sinon.spy(); | ||
let spyComponent = sinon.spy(); | ||
let componentA = new Horpyna.Component((request, response) => { | ||
@@ -104,7 +127,7 @@ setTimeout(() => { | ||
it("should return promise in run method and resolve it", (done) => { | ||
var spyA = sinon.spy(); | ||
var spyB = sinon.spy(); | ||
var spyC = sinon.spy(); | ||
var spyD = sinon.spy(); | ||
var spyComponent = sinon.spy(); | ||
let spyA = sinon.spy(); | ||
let spyB = sinon.spy(); | ||
let spyC = sinon.spy(); | ||
let spyD = sinon.spy(); | ||
let spyComponent = sinon.spy(); | ||
let componentA = new Horpyna.Component((request, response) => { | ||
@@ -111,0 +134,0 @@ setTimeout(() => { |
Sorry, the diff of this file is not supported yet
74325
28
829