Airstream
Airstream copied to clipboard
Add splitByIndex
Airstream provides a split
operator that can used to improve the rendering performance of a list of elements.
However this only works if the element can be mapped to a unique key (or in other words, the list has no duplicates).
A list with duplicates could be handled by using the index of an element as a key. WDYT?
Hm... seems like splitByIndex
can be DIY-d with something like observable.map(_.zipWithIndex).split(_._2)(...)
?
What are you rendering that you care to reuse elements by index – logs or something? There's also children.command
in Laminar for special cases. Its use case is quite limited, but really works well when that's what you need.
I have Signal
containing a list of non-unique elements that each map to an image.
Using observable.map(_.zipWithIndex).split(_._2)(...)
works but requires creating an intermediate list.
I'd like to hear if anyone else wants this. Adapting the current implementation of split
would complicate the code used for all existing usages of split
. Alternatively, writing a separate implementation that's mostly redundant would not be very elegant (double that since a separate impl is required for streams and signals). So... I'll wait for more demand for this.