absowoot
I’ve read numerous threads on the forum about maintaining a global state and it appears that the consensus is to utilize ETS ala Cachex, Phoenix Live Session, etc. Before I head down that road, I wanted to see if anyone has tried handling global state with a sticky liveview.
I think I could use on_mount to send a message to a sticky liveview, which then responds back with data, but I’m unsure how to obtain the sticky liveview PID to send the request to once it has already been loaded. Perhaps this could be stored in a session (server or client-side) or is there a a Liveview function to see all liveviews for a session?
Are there security concerns that would need to be considered?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
Perhaps you’re using this in a way that is different from what I understand but I don’t see how this is makes sense. If you have multiple connected liveviews, which is the source of truth? What if that source goes away and is never seen again?
What sort of state are you working with and what do you mean by “global”?
absowoot
Sorry, I should have clarified! By global state, I mean per user ie. a shopping cart for a user that may or may not be logged in.
For context, the app I’m working on is powered by third parties – user, carts, and products all come through API calls. The cart lives in a sticky liveview and its data is also used on a few pages, so the API is called multiple times while navigating the website. I was looking to have the cart in my sticky liveview be the source of truth for these pages instead of hitting the API since the data has already been fetched.
benwilson512
Sure but the thing I want to emphasize is that a live view is not 1:1 to a user, and liveviews go away when people aren’t looking at them sticky or not. “Sticky” just allows you to have state preserved between page redirects, it doesn’t keep state around when you close your browser. If you have 2 tabs open you have two different sticky liveviews.
absowoot
The cart ID is stored in a cookie and is updated through a broadcast so I think that would cover those scenarios.
Based on your responses, feels like this isn’t a good solution and I would be better off using an alternative method?
benwilson512
The cart ID or the cart contents? It sounds like you’re saying that the cart contents would be in the liveview, or is the cart contents in the cookie too?
absowoot
The cart ID lives in a cookie, which is then used to fetch the cart contents from the API. When products are added/removed, a new cart contents map is broadcasted using the cart ID to browsers that are subscribed to that ID.