harmon25

harmon25

Redex - Predictable Server Side State Containers - à la Redux for Elixir

https://github.com/harmon25/redex

Here is part of a proposal/idea for bringing server side state - I.E LiveView minus the view bit - into an SPA or whatever UI. I envision this working on mobile, web, maybe even Scenic, does not need to be coupled to JavaScript or Phoenix.

This is following up on the thread: Phoenix LiveView vs SPA - #48 by harmon25

I have played around a bit with the API and it is very doable - still some work to finalize it. Not in a currently working state - but should be soon.

I am sure people who are fully sold on LiveView and using it in its current state don’t really get why.
The flip side are all of us who have spent the last 5+ years mastering the JS stack/ecosystem, and just cant throw out the baby with the bathwater…

So, onto the real questions.

  1. Is this a good idea? :stuck_out_tongue:
  2. The API look OK?
  3. Foreseeable challenges or issues?

Thanks everyone who gave this a read!

Most Liked

sb8244

sb8244

Author of Real-Time Phoenix

I’m not sure what it would look like, but it would be interesting to see this integrated into redux as a proxy that reflects the state and updates it based on changes (from Channels). Bonus points if it can be combined with an existing store so that you can have some client side redux state if necessary (not everything is serializable).

I’m a huge fan of redux, and I think that a lot of interesting use cases can come from separating your store across boundaries. An example of this is the webext-redux library, which allows for redux state to live across a Chrome extension background/foreground boundary.

One use case that becomes trivial to implement if the redux state is synced with the server is that you could have 2 different pages staying in sync with each other by subscribing to the same state reference on the server.

KekKekington

KekKekington

So if I understood correctly you’d be able to use whichever frontend library you want and keep state on the server? That sounds very cool and could mean a bit more flexibility to select tools for a project.

harmon25

harmon25

Yep, that’s the idea!

Last Post!

harmon25

harmon25

I did think about this. It is an awful lot of processes for just a map.

There maybe a tiny concurrency benefit when ‘casting’ the action down the tree.(if it’s big enough)..but probably doesn’t outweigh the msg overhead. Also have not really tried, but failure may also be isolated…an action that crashes a reducer might some how be recoverable at only that level and below on the state tree…

Am considering @sasajuric ‘Parent’ to flatten that tree…each aggragate reducer is a genserver and a dynamic supervisor… So could remove atleast 3 processes from that tree I believe.

If my thoughts are wrong, would definately consider a simpler design…

Every stateful LiveView is a process, so if they can do it… :stuck_out_tongue:

Thanks for checking it out!

Where Next?

Popular in Discussions Top

CharlesO
Erlang :list.nth simple, but 1 - based nth(1, [H|_]) -> H; nth(N, [_|T]) when N > 1 -> nth(N - 1, T). Elixir Enum.at … coo...
New
MarioFlach
Hello, I want to share a project I’ve been working on for a while: https://github.com/almightycouch/gitgud Background Some time ago I ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
pillaiindu
I want to convert a Phoenix LiveView CRUD website to a CRUD mobile app. What do you think is the easiest way to do so?
New
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New
fireproofsocks
I’ve been working on an Elixir project that has required a lot of scripting. I usually reach for Elixir because I like it more (and in th...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement