jeffrey
Hello.
I use Drab and I want just to change the value of assign inside of a loop.
I have this loop code:
<%= for page <- @holder.pages do %>
<%= if page.id == @page_id do %>
<tr>
<td><%= page.title %></td>
</tr>
<% end %>
<% end %>
I change @page_id like this:
Drab.Live.poke(socket, page_id: id)
This function called when clicking on a button.
Everything works just fine when I place @page_id on some static element like h1.
But it doesn’t work inside of the loop.
Error: undefined function page/0
Can someone explain me why does it happen? I think Drab doesn’t fully reload loop - only if expression.
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
jeffrey
I tried to place this loop logic to commander function like this:
But I got
nilinstead ofpage.I have no idea what’s wrong with this code. I tried a lot of tricks and workarounds.
OvermindDL1
Oh @grych, you around? I think the embedded order of data holding is a bit off. ^.^
@jeffrey You may want to report this on the Drab issue tracker.
grych
Hi @OvermindDL1, thanks for waking me up from my winter hibernation
Hi @jeffrey, I will take a look and will get back to you. It might be a limitation of how Drab is processing the code blocks (inside do…end), I am not sure if it is properly documented (here).
grych
Unfortunately, it is not a bug. This is a limitation of Drab.Live’s local variables scope && the way how Drab is replacing parts of the page with the evaluated expression with new assign values.
When you’re
pokingthe new version of assign@page_id, Drab tries to update it in every expression on a page, which contains that value. In this case, it isif page.id == @page_id, do:.... But in the particular moment it does not know the value ofpagevariable - that’s why it shows undefined function page() while evaluating this expression.It is done by purpose. I could search expressions for assigns in their
do..endblocks, and re-render the the wholeforcomprehension while changing@page_id. And actually it was made like this before, but I realized that in the real world it provides to full reload of almost the whole page and more issues, like #42.In this particular situation, when you poke
@page_id, you really want to update the wholeforcompehension. One of the solution would be to put@page_idassign in the comprehension filter:This moves
@page_idto theforexpression, and now, after youpokeit, it re-evaluates the whole one.I know it is not very intuitive, but so far I couldn’t find the better solution.
Anyway, please create an issue on github, this situation needs more explanation/docs and/or at least the better error description. Probably it should not even compile.
Docs: Drab.Live.EExEngine – drab v0.10.5
jeffrey
Ok. Thanks for explaining!
grych
I’ve got the idea on how to make such things easier to maintain for a developer. What about if you can leave your code as it is, and ensure the parent comprehension is refreshed by just updating both assigns?
(or even introduce new API)
In the current version poking both assigns will generate the same error, because Drab will try to update
@page_idanyway, even if it is completely pointless as it is inside theforcomprehension, which is updated anyway.Drab should be aware of such cases and update only the parent statement. It would be also a performance improvement.
jeffrey
Btw I tried to update both assigns when I was looking for solution. So I think it’s intuitive.
But I think new API for updating additional assigns even more intuitive.
grych
Cool. I will do that, one more small step for Drab to be better!
grych
It is solved now, the change will be included in 0.7.1.
Solution for your case:
I did not introduce a new API for
poke, as I don’t want to add a special options likerefresh_assigns. You may have an assign named@refresh_assignsin you pageIf you have an idea for a good API for this case, please do not hesitate.