blazejcm

blazejcm

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!

Showing Posts 1 to 5

Hermanverschooten

Hermanverschooten

The only way I have found to do this, is to “enrich” your item with it’s index.
You cannot just use Enum.with_index/1 because stream requires your item to be a Map with an :id.

mudasobwa

mudasobwa

Creator of Cure

I must be missing something, but would not Stream.with_index/2 do?

Hermanverschooten

Hermanverschooten

We are talking about a Phoenix.LiveView stream, not Elixir.Stream.
Confusing that they chose the same term.

blazejcm

blazejcm OP

Thanks for clarifying!

I can’t “enrich” the item because of sorting and filtering options in my view. The items may be displayed in a different order every time.

I will have to live with the cloned items appearing at the bottom of the view.

All the best,
Michal

blazejcm

blazejcm OP

But I was thinking… I’ll try accessing the items in my stream in handle_event, finding the right item and figuring out its index. Maybe it will work.

Cheers!

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
mnkhod
So i have been using ash framework for a while and i love it. However currently the issue im having with ash framework is the error handl...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews