trueadm / t7

Lightweight virtual DOM templating library
900 stars 31 forks source link

Template key is not reliable #1

Closed ysegorov closed 9 years ago

ysegorov commented 9 years ago

Just a note on template key generation.

Considering this strange code

var s = 1,
    a = t7`<ul>${s}</ul>`,
    b = t7`<ol>${s}</ol>;
console.log(a, b);

we will have the following in console

Object { tag: "ul", attrs: Object, children: "1" } Object { tag: "ul", attrs: Object, children: "1" }

As for the library - excellent idea, Dominic! :)

trueadm commented 9 years ago

Thanks for trying t7 out and thank you for finding that bug. :)

ghost commented 9 years ago

@trueadm Why don't you just use template.join() for the cache key?

trueadm commented 9 years ago

@joelrich Large strings for cache key results in slower lookup times than hashed results.

ghost commented 9 years ago

Have you verified that? I am asking because such property access of is very likely implemented as a hashtable (which does basically the same, just implemented in C).

trueadm commented 9 years ago

In C, you have a limit on hashtables in terms of the key. Same applies here, especially with very large strings. Also, you should avoid using string.join() if you can avoid it as it's quite slow in all browsers.