You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many Javascript functions in Knetminer renders big blocks of HTML, such as tables, by using HTML string embedded in the code and with a line-by-line approach.
This is dirty, poorly readable and hard to maintain. We should start migrating those functions that have a high number of lines like this towards something better, such as a template-like mechanism.
Some of the elements that improve this kind of code are:
avoid table += ..., even less table = table + .... Use multi-line strings, use per-row functions, including anonymous/lambda functions
avoid "<string>" + variable + "<string>". Use interpolation via ${variable}
Separate (as much as possible) HTML code from computations, using, among other things, interpolation, variables defined at the top of a rendering block, multi-line definitions in a file (for bigger blocks), lambdas.
Another approach is to load an empty HTML and then manipulate the DOM, as in here. The former seems simpler to me, but I'm open to discussion.
The text was updated successfully, but these errors were encountered:
Many Javascript functions in Knetminer renders big blocks of HTML, such as tables, by using HTML string embedded in the code and with a line-by-line approach.
For instance:
This is dirty, poorly readable and hard to maintain. We should start migrating those functions that have a high number of lines like this towards something better, such as a template-like mechanism.
For instance, this is a good first example.
Some of the elements that improve this kind of code are:
table += ...
, even lesstable = table + ...
. Use multi-line strings, use per-row functions, including anonymous/lambda functions"<string>" + variable + "<string>"
. Use interpolation via${variable}
Another approach is to load an empty HTML and then manipulate the DOM, as in here. The former seems simpler to me, but I'm open to discussion.
The text was updated successfully, but these errors were encountered: