revati

revati

Proposal: send_update accept cid

Hello, currently, to call send_update, i have to pass destination module and id (which is more of an html id than elixir side id - at least how i interpret it).

If i have live_component nested in another live component i do this currently

# Parent
<.live_component
  module={ChildComponent}
  id={"#{id}-child"}
  parent={{__MODULE__, id}}
/>
# Child
def handle_event("...", _, socket) do
  {parent_module, parent_id} = socket.assigns.parent
  send_update(parent_module, id: parent_id, action: my_payload)
end

I looked under the hood and all parent_module, id: parent_id does is gets cid to call further call correct callback (found by cid).

Wouldn’t it be easier just to

# Parent
<.live_component
  module={ChildComponent}
  parent={@myself}
/>
# Child
def handle_event("...", _, socket) do
  send_update(socket.assigns.parent, action: my_payload)
end
  1. if no id is given cid is used as id
  2. both live views and live components have cid
  3. cid can be used to call send_update to any target (both live views and live components).
  4. live views might aswell have update callback to handle those cases.

This also would move towards implementing this this:Provide a unified mechanism to message the parent/child · Issue #1597 · phoenixframework/phoenix_live_view · GitHub

Most Liked

atomkirk

atomkirk

Yes please! A case where i needed this was an autosuggest component. Arrow keys move slection up and down list of options, enter should select it and tell the parent. Theres no way to send a message to the parent programmatically!

Where Next?

Popular in Proposals: Ideas Top

virinchi_cv
The Problem Phoenix 1.8 comes aggressively coupled with Daisy UI, a decision which many developers in the community have had mixed feelin...
New
andypearson
Hey all, I have been working on some performance improvements for the Phoenix application I work on. As part of this, through trial and...
New
marcandre
I notice that most events have bindings (e.g. phx-keyup) but not the input event. The input event is the preferred way to interact with ...
New
jakeprem
Goal: To make JS.patch and JS.navigate more interoperable with JS.push. Scenario: Imagine making a reusable Phoenix component and you wa...
New
bianchidotdev
I came across a blog post that implemented a function guard for a liveview socket connection’s presence. It seems like a really ergonomic...
New
cevado
IEx is a very powerfull shell and it would be awesome to have all this power integrated inside a code editor. Clojure enables something l...
New
mortenlund
Hi! I would like to suggest a new callback in the lifecycle of the Live Component which is unmount. Sometimes it is nice to be able to ...
New
bamorim
Story behind Recently, I gave a talk on a meetup about improving performance of Phoenix applications and the example app was a LiveView ...
New
caslu
Recently (last week) this PR was merged in Ruby on Rails repository and i thought it could be nice to have in phoenix, basically what it ...
New
dimitarvp
To @jonatanklosko and @the-mikedavis: I see that there is a Rust crate at crates.io: Rust Package Registry but it is pointing at https:/...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

We're in Beta

About us Mission Statement