dkuku

dkuku

Helpers for {:noreply, socket} that can be used with pipes

Currently we have to write this way which is a bit convoluted

socket =
   socket
  |> assign(valid: true)
{:noreply, socket}

Please include functions to write like for the most popular values just two for :ok and :noreply make my file look much cleaner

socket
|> assign(valid: true)
|> noreply()

I can add it myself as helpers but would be nice to have it included in the framework

Most Liked

rkma

rkma

You could do this:

{:noreply, assign(socket, :valid, true)}
dkuku

dkuku

I know but I just refactored this:

  def handle_event("validate",  %{"command" => command} = params, socket) do
    socket = 
      socket
      |> assign(valid: valid_code?(command, socket.assigns.binding))
    {:noreply, push_patch(socket, to: self_path(socket, socket.assigns.menu.node, params))}
  end

  @impl true
  def handle_info({:node_redirect, node}, socket) do
    {:noreply, push_redirect(socket, to: self_path(socket, node, socket.assigns.params))}
  end

To


  @impl true
  def handle_event("validate", %{"command" => command} = params, socket) do
    socket
    |> assign(valid: valid_code?(command, socket.assigns.binding))
    |>  push_patch(to: self_path(socket, socket.assigns.menu.node, params))
    |> noreply() 
  end

  def handle_info({:node_redirect, node}, socket) do
    socket
    |> push_redirect(to: self_path(socket, node, socket.assigns.params))
    |> noreply() 
  end

Its much more readable. I was even thinking to create a library for that, but I it would be good to have it inside phoenix

  def noreply(socket), do: {:noreply, socket}

Where Next?

Popular in Discussions Top

jswny
I would like to better understand what the advantages/disadvantages of umbrella applications are compared to structuring your app as as s...
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
arpan
Hello everyone :wave: Today I am very excited to announce a project that I have been working on for almost 3 months now. The project is...
New
Ankhers
Just a little information upfront. Generally speaking, if I feel like I need to either break a pipe chain or use an anonymous function in...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31265 143
New
marciol
Please, let me know if this kind of discussion already took place in another topic . Hi all, how do you consider if is better to build ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
New
sashaafm
Piggy backing a bit on @dvcrn topic BEAM optimization for functions with static return type?, I’ve been trying to understand in a deeper ...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48342 226
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43757 214
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement