|
|
|
|
|
by ianbicking
674 days ago
|
|
Hey Paul! I think JSX is an example of the somewhat crude but practical use of simple execution patterns. For instance if you have a loop you do: return <ol>
{items.map((item, i) => <li key={i}>{item}</li>)}
</ol>;
Which isn't really templating at all, but just the ability to use inline expressions and easily construct objects does get the job done.Or in a SQL builder with JavaScript tagged templates, I do: exec(sql`
SELECT * FROM a_table
WHERE category = ${category}
${subcategory ? sql`AND subcategory=${subcategory}` : sql``}
`)
That is, I nest tagged templates to handle different logic conditions and loops.If there's deferred execution, it's done with ?: and .map() – though these very long expressions don't work nearly as well in Python. (List comprehension is in some ways better than .map()/.filter(), but not for very large expressions like in a JSX template.) |
|