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
You could do this:
{:noreply, assign(socket, :valid, true)}
1
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}
1
Popular in Discussions
I would like to better understand what the advantages/disadvantages of umbrella applications are compared to structuring your app as as s...
New
I wanted to capitalize a string, and tried using String.capitalize().
That generally works well, until you try to capitalize a word like...
New
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
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
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...
New
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
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
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
Release date is May 2017. Can’t wait for it.
New
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
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...
New
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
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
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
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
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
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
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
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
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
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









