Open xp1632 opened 1 month ago
eval()
do?So I checked some examples:
In the VP project, we are using eval()
to dynamically create a function
For example, we have a simple string to predefined a function in a node specification's JSON file as
nodeGenerator = "(${input1},${input2}) => ${input1} + ${input2}"
# which if we eliminate the `$` as formatted is:
nodeGenerator = "(input1,input2) => input1 + input2"
nodeSourceGeneration()
, we take this nodeGenerator
and put it into eval()
method, and let the string become a function
let nodeGenerator = "(input1, input2) => input1 + input2";
let func = eval(`(${nodeGenerator})`);
let result = func(3, 4); // result is now 7
To Summarize:
eval()
did in VP project is :from predefined string with ${input1}
to functioning source code method
However what we did in Pipeline is the backwards direction
since we don't want to manually write the ${}
decorated code
we replace the input parameter with ${inputs}
so it could later be recognized by eval()
in project and become a functioning method
from:
to
I don't see how we could use eval()
to accomplish the current function in pipeline, because they are working in different directions
But replace()
itself is also not that robust, especially when we have comments
that has same range
string that we replaced in code snippet.
What we could do are:
range
etc
refactored_v1_pipeline
replace()
and asked why don't I useeval()
method as he used in nodeSourceGeneration, where he generated functioning source code , from manual-written${}
formatted code in json