jorgebucaran / superfine

Absolutely minimal view layer for building web interfaces
https://git.io/super
MIT License
1.56k stars 78 forks source link

if-else case caused every element update #166

Closed yisar closed 4 years ago

yisar commented 4 years ago
const node = document.getElementById("app")

const setState = state => {
  patch(
    node,
    h("div", {}, 
      state && h("h1", {}, 'hello'),
      h("button", { onClick: () => setState(!state) }, "x")
    )
  )
}

setState(true)

I‘d seen that only keyd elements can be cached and reused, and elements like this are still completely updated. In fact, the following use case only needs to insert or remove hello

What do you think of this?

jorgebucaran commented 4 years ago

Insertions are difficult and in some cases impossible to optimize without keys, so use keys -- that's one of the reasons they exist.