node-webot / co-wechat

Wechat for Koa
427 stars 91 forks source link

Use template-literal instead of EJS #37

Open Drulac opened 6 years ago

Drulac commented 6 years ago

Template Literal is fastest, smallest and simplest template engine, because it use JS's literal template feature.

It's 55 times faster than EJS, and it also use less CPU and RAM ressources, so it may be a good idea to use it instead of EJS 😀

JacksonTian commented 6 years ago

Hi @Drulac The template literal not support complex condition struct.

Drulac commented 6 years ago

can you give me an example of complex condition struct please :-) ?

JacksonTian commented 6 years ago
<% if (a) { %>
balababala
<% } %>

<% for () { %>
babaljbljafa
<% } %>

and if else if, balabala

Drulac commented 6 years ago

Oh it's easy to make it with template literal :-)

${(a) ? : 'blablabla' : '' }
// or for more complex
${ (()=>{
    if (a) {
        return 'balababala'
    }
return '' //always return empty, to don't display null or undefined
})()}

using array methods like map, sort, filter, ... you can replace easily loops, or you can still use a function to do that