pyro87

pyro87

Halt liveview updates until client side animation is finished

Hey, just starting out with liveview and want to make sort of a game with it. The problem I’m having is with adding animations. To quickly explain how the game works: you have two dices, one is rolled at the start of a game, let’s say to a value of 3, the other dice however is hidden and will roll at the end of a game. Users can place their guesses if the second dice value will be higher/lower or equal. Users have 10 seconds to place their guesses and at the end of that time the second dice reveals it’s value.

The issue that i’m having is that at the end of the timer we basically switch out the current round for a new one on the server and new guesses start pouring. What’s the proper way for me to halt new updates from liveview until an animation that reveals the second dice is finished?

Most Liked

soup

soup

If you trigger the animation via a JS command, it should block any events until it finishes, in my experience. You could fill that with a dummy animation/time to cover your real animation if you cant trigger it via a JS command for whatever reason.

Probably the simplest way without having your own timers and stuff.

kartheek

kartheek

In game development, it can be done in two ways:

  1. Actions are chained and updates are executed using a queue.
  2. flags are used to disable few elements based on it - example isAnimating flag will prevent new animations from triggering until current animation is complete.

You can try out these techniques in LiveView to solve your problem.

Only client side fixes won’t solve this issue completely - something on the server side will have to coordinate these.

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
saveman71
Hello ! We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement