You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Both approaches work fine on first render and then never again. I assume that's because the overloaded map and iterator turn into generator functions? Generator functions are probably not very useful for hdom if they can only run once. However, it looks like iterators can also be computed several times though I'm not sure that's desirable.
Getting back to the issue, is there a shorter way to express the list component above?
The text was updated successfully, but these errors were encountered:
den1k
changed the title
[hdom] - only once iterators disappear after initial render
[hdom] - iterators disappear after initial render
Sep 10, 2018
Iterators can of course only be consumed once, but they do make sense in many situations also in hdom. It all really depends on how your components are setup/created.
This will FAIL after first render:
start(["ul",tx.map((i)=>["li",i],tx.range(5))]);
The reason this fails is because the value passed to start() is the array ["ul", iterator], but then the iterator can only be consumed once... hence in the second frame the ul element will have no more children and so they'll be diffed away.
Here the spread operator forces the iterator to be realized before the array is passed to start(), so the array is really now a static piece of data ["ul", ["li", 0], ["li", 1], ....]
I was looking for a shorter way to write components that dynamically create inner child-nodes from a collection.
For example, a basic list component:
The transduce
transduce
and thepush()
seem superfluous to me. I tried:and
to compose transducers.
Both approaches work fine on first render and then never again. I assume that's because the overloaded map and iterator turn into generator functions? Generator functions are probably not very useful for hdom if they can only run once. However, it looks like iterators can also be computed several times though I'm not sure that's desirable.
Getting back to the issue, is there a shorter way to express the
list
component above?The text was updated successfully, but these errors were encountered: