WebReflection / hyperHTML

A Fast & Light Virtual DOM Alternative
ISC License
3.07k stars 113 forks source link

The docs example for how tagged template literals work is wrong #275

Closed slikts closed 6 years ago

slikts commented 6 years ago

A fiddle with the example; the "same unique Array" assertion fails: https://jsfiddle.net/slikts/zbwyhs3a/

Example in question: https://viperhtml.js.org/hyperhtml/documentation/#introduction-1

The reason the arrays are not the same is that it also needs to be the same template literal. Namely, instead of:

template`1 ${2} 3`; // 1 2 3
template`1 ${4} 3`; // 1 4 3

It should be wrapped in a function:

const foo = x => template`1 ${x} 3`;
foo(2);
foo(4);

Updated fiddle where the assertion works: https://jsfiddle.net/slikts/zbwyhs3a/5/

WebReflection commented 6 years ago

@slikts correct, you can read more in here why the example was like that: https://itnext.io/a-tiny-disastrous-ecmascript-change-fadc05c83e69

TL;DR they changed specs recently and I haven't had the time to catch up with the docs, any help welcome, thanks

spencerkordecki commented 6 years ago

Using the example @slikts provided, I opened a PR on the documentation repo here:

https://github.com/viperHTML/viperhtml.github.io/pull/30

WebReflection commented 6 years ago

thanks @spencerkordecki !