Hi all,
I've searched the forums, yet can't find anything that describes an answer to what I am looking for.
In a nutshell, I would like to control flow of my application be defined by an external flow input (file) in which the individual steps (functions) to call, their order and conditions are described.
Example code with hardcoded control flow:
// Code
function A(input){
return input * 2;
}
function B(input){
return input + 2;
}
function C(input){
return input / 2;
}
functionZ(input){
if(input==3) lowResult();
else highResult();;
}
function lowResult(){
console.log('Result smaller than 4');
}
function highResult(){
console.log('Result equal or larger than 4')
}
// flow 1
Z(C(B(A(2)))); // (((2 * 2) + 2) / 2) = 3 returns 'Result smaller than 4'
// flow 2
Z(B(C(A(2)))); // (((2 * 2) / 2) + 2) = 4 returns 'Result equal or larger 4'
Now what I am looking for is a library or approach that allows me to define flow 1 and flow 2 in a file and then have the code execute according to the defined flow. Best would be format that allows for conditions, etc as well.
<!-- FLOW 1 -->
<STEP function="A" />
<STEP function="A" />
<STEP function="A" />
<IF condition="==3">
<STEP function="lowResult" />>
<ELSE>
<STEP function="highResult" />
</IF>
That way different control flows could be easily composed by connecting a number of components.
Thanks for reading,
Phil