justin-schroeder / arrow-js

Reactivity without the framework
https://arrow-js.com
MIT License
2.38k stars 49 forks source link

Static string cleared from attribute #50

Closed zeenau closed 1 year ago

zeenau commented 1 year ago

Example:

const data = reactive({
  class:'css'
})
<li class="prefix-${() => data.class}-postfix" >Title</li>

renders to:

<li class="css" >Title</li>

instead of:

<li class="prefix-css-postfix" >Title</li>

notice "prefix/postfix" removed from the class attribute.

I understand that this can be refactored (to include all inside the function) but I'd expect static string before/after observable to be left unchanged.

This example is oversimplified but the idea is that template holds static values (to render even without dynamic part being set).

justin-schroeder commented 1 year ago

Yeah, I understand that it may seem intuitive for it to work that way, but it does not. Attributes are all or nothing — similar to many reactive frameworks where the expression is the value of the argument (in the <div :class="expHere">). It would be quite a lot more "expensive" in compute and memory to allow this types of arbitrary concatenation. If you want to perform string interpolation, just include that as the output of your fn.

Thanks for checking out arrow though!