Hi everyone!
I have a list of items that I display in Phoenix LiveView using streams.
Currently, I am working on the “Clone” feature. any item can be cloned and the new (cloned) item is supposed to appear right below the item being cloned.
I want to use stream_insert(..., at: position)
but for this to work, I need to know the relative position of every item on the list.
I tried a few variations of the following in my view:
:for={ {{dom_id, entry}, position} <- Enum.with_index(@streams.entries) }
but I get the following error:
streams can only be consumed directly by a for comprehension. If you are attempting to consume the stream ahead of time, such as with
Enum.with_index(@streams.entries)
, you need to place the relevant information within the stream items instead.
I have no idea how to proceed in a way that would be idiomatic. I am sure I can hack my way out of this - but there’s got to be “the right way” to do it…
Thanks in advance!