Comparing version 0.7.3 to 0.7.4
@@ -99,4 +99,8 @@ require("source-map-support").install(); | ||
var _errors = __webpack_require__(10); | ||
var _request = __webpack_require__(10); | ||
var _request2 = _interopRequireDefault(_request); | ||
var _errors = __webpack_require__(11); | ||
var ERROR = _interopRequireWildcard(_errors); | ||
@@ -157,3 +161,3 @@ | ||
this.rootComponent.run(endCallback); | ||
this._runProcess({ input: input }); | ||
this._runProcess([input]); | ||
} | ||
@@ -167,3 +171,3 @@ | ||
key: "_runProcess", | ||
value: function _runProcess(request) { | ||
value: function _runProcess(inputList) { | ||
var _this = this; | ||
@@ -173,3 +177,3 @@ | ||
setTimeout(function () { | ||
return _this.onProcess(request, new _response2.default(_this)); | ||
return _this.onProcess(new _request2.default(inputList), new _response2.default(_this)); | ||
}, 0); | ||
@@ -456,9 +460,5 @@ } | ||
value: function getOutput() { | ||
if (this.channels.length === 1) { | ||
return { input: this.channels[0].output, length: 1 }; | ||
} else { | ||
return { input: this.channels.map(function (channel) { | ||
return channel.output; | ||
}), length: this.channels.length }; | ||
} | ||
return this.channels.map(function (channel) { | ||
return channel.output; | ||
}); | ||
} | ||
@@ -550,12 +550,9 @@ }, { | ||
(function () { | ||
var output = []; | ||
var doneChannelList = []; | ||
_this.component.channelManager.channels.forEach(function (channel) { | ||
if (channel.status === STATUS.DONE) { | ||
output.push(channel.output); | ||
doneChannelList.push(channel); | ||
} | ||
}); | ||
if (output.length === 1) { | ||
output = output[0]; | ||
} | ||
_this.component.rootComponent.finish(output); | ||
_this.component.rootComponent.finish(doneChannelList); | ||
})(); | ||
@@ -596,3 +593,23 @@ } | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Request = function Request(outputList) { | ||
_classCallCheck(this, Request); | ||
this.input = outputList; | ||
}; | ||
exports.default = Request; | ||
/***/ }, | ||
/* 11 */ | ||
/***/ function(module, exports) { | ||
"use strict"; | ||
/***/ } | ||
/******/ ]))); |
{ | ||
"name": "horpyna", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"description": "utility to manage async processes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,2 +5,3 @@ import Root from "./root"; | ||
import Response from "./response"; | ||
import Request from "./request"; | ||
import * as ERROR from "../constants/errors"; | ||
@@ -40,3 +41,3 @@ import * as STATUS from "../constants/statuses"; | ||
this.rootComponent.run(endCallback); | ||
this._runProcess({ input }); | ||
this._runProcess([input]); | ||
} | ||
@@ -47,5 +48,5 @@ | ||
*/ | ||
_runProcess(request) { | ||
_runProcess(inputList) { | ||
this.status = STATUS.PROCESS; | ||
setTimeout(() => this.onProcess(request, new Response(this)), 0); | ||
setTimeout(() => this.onProcess(new Request(inputList), new Response(this)), 0); | ||
} | ||
@@ -52,0 +53,0 @@ |
@@ -14,7 +14,3 @@ import Channel from "./channel"; | ||
getOutput() { | ||
if(this.channels.length === 1) { | ||
return { input: this.channels[0].output, length: 1 }; | ||
} else { | ||
return { input: this.channels.map(channel => channel.output), length: this.channels.length }; | ||
} | ||
return this.channels.map(channel => channel.output); | ||
} | ||
@@ -21,0 +17,0 @@ |
@@ -35,12 +35,9 @@ import * as STATUS from "../constants/statuses"; | ||
} else { | ||
let output = []; | ||
let doneChannelList = []; | ||
this.component.channelManager.channels.forEach(channel => { | ||
if (channel.status === STATUS.DONE) { | ||
output.push(channel.output); | ||
doneChannelList.push(channel); | ||
} | ||
}); | ||
if(output.length === 1) { | ||
output = output[0]; | ||
} | ||
this.component.rootComponent.finish(output); | ||
this.component.rootComponent.finish(doneChannelList); | ||
} | ||
@@ -47,0 +44,0 @@ } |
@@ -26,3 +26,3 @@ import sinon from "sinon"; | ||
component.final(); | ||
component.run(null, output => { | ||
component.run(null, channelList => { | ||
spyComponent(); | ||
@@ -32,3 +32,3 @@ expect(spyComponent.calledOnce).to.be.true; | ||
expect(spyCustomFunc.calledBefore(spyComponent)).to.be.true; | ||
expect(output).to.be.equal(TEST_MESSAGE_A); | ||
expect(channelList[0].output).to.be.equal(TEST_MESSAGE_A); | ||
done(); | ||
@@ -60,3 +60,3 @@ }); | ||
component.final(); | ||
component.run(null, output => { | ||
component.run(null, channelList => { | ||
spyComponent(); | ||
@@ -66,3 +66,3 @@ expect(spyComponent.calledOnce).to.be.true; | ||
expect(spyCustomFunc.calledBefore(spyComponent)).to.be.true; | ||
expect(output).to.be.equal(TEST_MESSAGE_B); | ||
expect(channelList[0].output).to.be.equal(TEST_MESSAGE_B); | ||
done(); | ||
@@ -72,7 +72,9 @@ }); | ||
it("should throw error if component doesn't have function logic", done => { | ||
it("should output response from first channel list and response is single element array", done => { | ||
let component = new Horpyna.Component(); | ||
component.final(); | ||
component.run(TEST_MESSAGE_A, output => { | ||
expect(output).to.be.equal(TEST_MESSAGE_A); | ||
component.run(TEST_MESSAGE_A, channelList => { | ||
expect(channelList.length).to.be.equal(1); | ||
expect(channelList[0].output.length).to.be.equal(1); | ||
expect(channelList[0].output[0]).to.be.equal(TEST_MESSAGE_A); | ||
done(); | ||
@@ -86,3 +88,3 @@ }); | ||
onProcess(request, response) { | ||
response.send(request.input); | ||
response.send(request.input[0]); | ||
} | ||
@@ -92,3 +94,3 @@ }; | ||
onProcess(request, response) { | ||
expect(request.input).to.be.equal(TEST_MESSAGE_A); | ||
expect(request.input[0]).to.be.equal(TEST_MESSAGE_A); | ||
response.send(); | ||
@@ -111,4 +113,4 @@ done(); | ||
onProcess(request, response) { | ||
expect(request.input).to.be.equal(TEST_MESSAGE_A); | ||
expect(request.length).to.be.equal(1); | ||
expect(request.input[0]).to.be.equal(TEST_MESSAGE_A); | ||
expect(request.input.length).to.be.equal(1); | ||
done(); | ||
@@ -141,3 +143,2 @@ } | ||
expect(request.input.length).to.be.equal(2); | ||
expect(request.length).to.be.equal(2); | ||
done(); | ||
@@ -279,3 +280,3 @@ } | ||
spyB(); | ||
expect(request.input).to.be.equal(TEST_MESSAGE_A); | ||
expect(request.input[0]).to.be.equal(TEST_MESSAGE_A); | ||
response.send(); | ||
@@ -308,3 +309,3 @@ } | ||
onProcess(request, response) { | ||
if (request.input) { | ||
if (request.input[0]) { | ||
spyAB(); | ||
@@ -311,0 +312,0 @@ response.send(null, CHANNEL_AB); |
Sorry, the diff of this file is not supported yet
92968
34
1183