flowie
Version:
Library for creating, and working with flows
4 lines • 3.27 kB
JavaScript
(function(){function generateFlowFunction(it
) {
var out=''; const asyncPreffixOrNot = it.isAsync ? 'async ': ''; const contextOrNot = it.includeContext ? `, context` : ''; var arr1=it.subFlows;if(arr1){var subFlow,i1=-1,l1=arr1.length-1;while(i1<l1){subFlow=arr1[i1+=1];out+=' '; const asyncPreffixOrNotForFlow = subFlow.isAsync ? 'async ' : ''; out+=' '; const [lastStepSubFlow] = subFlow.steps.slice(-1); out+=' '; const hasGeneratorsSubFlow = Boolean(lastStepSubFlow.finishGeneratorsCount); out+=' '; const reduceWhenLastIsFinishGeneratorsOnSubFlow = Number(hasGeneratorsSubFlow); out+=' '+(asyncPreffixOrNotForFlow)+'function executeFlow_'+(subFlow.hash)+'({ flowieContainer, reporter, argument'+(contextOrNot)+' }) { let reportsList = []; ';var arr2=Object.values(subFlow.functionsFromContainers);if(arr2){var functionName,i2=-1,l2=arr2.length-1;while(i2<l2){functionName=arr2[i2+=1];out+=' const executeFunction_'+(functionName)+' = flowieContainer.functionsContainer.'+(functionName)+'.flowFunction; ';} } out+=' ';if(hasGeneratorsSubFlow){out+=' ';var arr3=subFlow.steps.slice(0, subFlow.steps.length - reduceWhenLastIsFinishGeneratorsOnSubFlow);if(arr3){var step,index=-1,l3=arr3.length-1;while(index<l3){step=arr3[index+=1];out+=' let result'+(index+1)+'; ';} } out+=' let reportOnGenerator; ';}out+=' ';var arr4=subFlow.steps;if(arr4){var step,index=-1,l4=arr4.length-1;while(index<l4){step=arr4[index+=1];out+=' '+(it.generateFlow(it, { step, parentIndex: index, hasGenerators: hasGeneratorsSubFlow }))+' ';} } out+=' return [reportsList, result'+(subFlow.steps.length - reduceWhenLastIsFinishGeneratorsOnSubFlow)+']; }';} } const [lastStep] = it.mainFlow.steps.slice(-1); const hasGenerators = Boolean(lastStep.finishGeneratorsCount); const reduceWhenLastIsFinishGenerators = Number(hasGenerators); out+='return '+(asyncPreffixOrNot)+'function executeMainFlow(executionArguments) { '+(it.shouldDebugFlow ? 'debugger;' : '')+' const { flowieContainer, argument, flowieResult, reporter'+(contextOrNot)+' } = executionArguments; let reportsList = []; const startHRTime = process.hrtime(); ';var arr5=Object.values(it.mainFlow.functionsFromContainers);if(arr5){var functionName,i5=-1,l5=arr5.length-1;while(i5<l5){functionName=arr5[i5+=1];out+=' const executeFunction_'+(functionName)+' = flowieContainer.functionsContainer.'+(functionName)+'.flowFunction; ';} } out+=' ';if(hasGenerators){out+=' ';var arr6=it.mainFlow.steps.slice(0, it.mainFlow.steps.length - reduceWhenLastIsFinishGenerators);if(arr6){var step,index=-1,l6=arr6.length-1;while(index<l6){step=arr6[index+=1];out+=' let result'+(index+1)+'; ';} } out+=' let reportOnGenerator; ';}out+=' ';var arr7=it.mainFlow.steps;if(arr7){var step,index=-1,l7=arr7.length-1;while(index<l7){step=arr7[index+=1];out+=' '+(it.generateFlow(it, { step, parentIndex: index, hasGenerators }))+' ';} } out+=' return flowieResult.success(result'+(it.mainFlow.steps.length - reduceWhenLastIsFinishGenerators)+', startHRTime, reportsList);}';return out;
}var itself=generateFlowFunction;if(typeof module!=='undefined' && module.exports) module.exports=itself;else if(typeof define==='function')define(function(){return itself;});else {window.render=window.render||{};window.render['generateFlowFunction']=itself;}}());