tomazbracic

tomazbracic

Liveview "mount" and big preprocessing

Hi

I am using elixir full stack with liveview. I am building a dashboard application which will be heavy on data from database, pubsub etc. Especially from database, there will be data for charts for their multi series, single stats, forecasts, etc. But when data comes from database it still needs to be (pre)processed a bit, to push it into right structure for JS Charts.js data/datasets, and uses it for line charts, etc.

So for charting I am using Charts.js via JS.hooks.

So, is this something you would do inside mount function or you would do it somehow different or somewhere else. I mean with Genserver it is what you would use handle_continue for. So that you have fast startups of genserver processes.

I feel something similar should be the approach with mount function of liveview… or am I mistaken? I guess we don’t want it to be slow with fetching data from DB, manipulating it, because with huge amount of data this can be time consuming. But at the same time I don’t think you can do any better if you just push the logic into some other module, file, location.

What would be the best practice/approach here? Beside pushing this to something else than mount function. Use the mount function to only set empty structures and perhaps to “handle loading” state and visual appearence of spinner suggesting that not all the data is ready yet. And somehow trigger something like Task.async to fetch data? Perhaps from mount? I mean, can/should I use handle_continue in liveview or send a message to myself with send(self()… and catch that with handle_info and do data processing there? What would you suggest?

Thanks in advance for your feedbacks

Tomaz Bracic

Most Liked

al2o3cr

al2o3cr

This sounds like exactly the scenario that assign_async was designed to handle.

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
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

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
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
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
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
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement