Repository navigation
Conversation
|
I think we can omit the null prototype step for this library - it's extremely unlikely to result in a collision if any kind. For keys, why not use |
|
Yeah, the collisions are very unlikely. Reverted that change. Using let key = '', i = 0;
while (i < statics.length) {
key += statics[i].length + '$' + statics[i++];
}should give a unique cache key for every distinct array of statics, so that'd be one less thing to worry about. The solution seems to compress pretty well, merged to the current master htm.mjs.gz takes 710 B, up from 688 B. When merged to #21 htm.mjs.gz still takes 696 B. For some reason this change also seems to yield a modest performance increase in my development environment. Running After this change the numbers become: I've made the changes suggested above to this branch and rebased it. However, say if you want to go with the |
|
Force pushed the rebased version. |
|
Modified the implementation a bit, dropping the gzipped size to 708 B. |
|
Closing this in preparation to #38. |
Currently the results for parsed templates get cached, the cache key being the statics joined with
,. It's possible to accidentally have two different tagged templates that have the same cache key. For example<div>Hello, World!</div>and<div>Hello${comma} World!</div>would both have<div>Hello, World!</div>as their cache key.This pull request attemps to fix that and add a relevant test. Cache keys are now created by prefixing underscores and commas in statics by with an additional underscore
_, and then joining these modified statics. This should (?) ensure that cache keys are unique. The cache object is also now created viaObject.create(null)to ensure that it doesn't have a prototype and therefore keys likehasOwnPropertydefined.Unfortunately this affects the performance. Max. impact seems to be 5% slowdown in my development environment. The bundle size is also larger: Merged to the current master htm.mjs.gz takes 715 B, up from 688 B. When merged to #21 htm.mjs.gz takes 696 B.