HORPYNA

SHORT DESCRIPTION
This module is for better organizing multiple async processes.
If you have:
- big amount async functions
- some of them run only if some conditions meet
- some of them run multiple times
- you are bored of long promise chains with inner conditional sub chains
- you want to reuse some parts of promise chains
Then this library is for your project!
It helps with modularity, reusability and testify of your code.
HOW DOES IT WORKS
You split your code into smaller independent parts. Each of them you wrap into Horpyna Component. You customize
each component. And then it is funniest part. You can join components together, then built new components from
joined components. You can decorate components with other components to modify it functionality.
For example you can have component which consist of 5 other components. You can reuse it, and remove some inner components
and replace them with other components.
It is also easy to test. Each component have input and output. In test you set different input data and test
output values.
INSTALLATION
npm install horpyna
USAGE
in ES6 syntax but you can use it with ES5 too
EXTENDING COMPONENT
You have to separate your code into smallest code blocks, then create new classes which extending from Horpyna.Component
and put in each class your code block
import Horpyna from "horpyna";
class CustomComponent1 extends Horpyna.Component {
onInit() {
//custom configuration, for example creation of additional channels
}
onProcess(request, response) {
//input data is available from request.input
//when component finish calculating response send it via response.send(componentResponse)
}
}
export default CustomCOmponent1;
YOU SHOULD BUILD COMPONENTS WITH OPTIONS WHICH SHOULD ALLOW YOUR COMPONENTS TO BE FLEXIBLE
if you wish create your components inline
:
let CustomComponent1 = class extends Horpyna.Component {
onInit() { ... }
onProcess(request, response) { ... }
}
or even create instances from inline classes
let customComponent1 = new class extends Horpyna.Component {
onInit() { ... }
onProcess(request, response) { ... }
}
BUILDING COMPONENT CHAINS
*Your work consists of two parts: create components, create components chains based on your components (or external)
Let assume that we have components in files (components looks like above):
validateParams.js
sendErrorMessage.js
getEnityFromDb.js
calculateSomething.js
sendResponse.js
import ValidateParams from "validateParams";
import SendErrorMessage from "sendErrorMessage";
import getEnityFromDb from "GetEnityFromDb";
import CalculateSomething from "calculateSomething";
import SendResponse from "sendResponse";
let validateParams = new ValidateParams();
let
let validateParams = new SendErrorMessage();
API
LICENSE
MIT