princemaple
TLDR: https://minesweeper.fly.dev built with liveview and other recent tools.
Most relevant code at mine_sweeper/lib/mine_sweeper_web/live/session_live at main · princemaple/mine_sweeper · GitHub
Hi All,
My most familiar stack is building frontend with Angular and using phoenix as an API backend. I briefly tried liveview when it first came out. That was pre-heex, pre-component era. I’ve been wanting to try the shiny new stuff and stay up to date.
I could’ve chosen a different game if I simply wanted to build something interactive and realtime. I chose minesweeper because 1. it’s one of my favorite games, 2. it requires a lot of state keeping and inter-component communication (I initially thought each component would be a separate process) and 3. it requires quite a bit interaction (event handling). I thought it’s a good game to build to test all these things out.
Plus, there has been a couple other things on my listing waiting to be checked out.
- fly.io deployment
(I’ve used the one-click to launch livebook. It’s great) - phoenix with esbuild and tailwind
(they are not new to me, I just haven’t built a phoenix app that uses them to build the assets)
So, I decided to build this minesweeper game with liveview, with the assets built with esbuild & tailwind, and deployed to fly.io
A few notes:
- as previously mentioned, I initially thought each component was a separate process. That wasn’t the case. So there isn’t really much “inter-component communication”. I built the game with GenServers, while liveview and components were solely used to render and interact.
forinheexseems to update all or nothing. I thought it would be able to only update the ones with thier assigns changed. Easy workaround though, just check the new assigns with the assigns on socket.- somewhat often, changes in assets, sometimes also in GenServers, don’t get reflected in the running app. Not sure if building on Window directly had something in it. I normally dev with docker and this is not an issue.
Overall everything went pretty smoothly.
GitHub - phoenixframework/esbuild: An installer for esbuild · GitHub and GitHub - phoenixframework/tailwind: An installer for tailwind · GitHub do a very good job getting me started, and provide very sensible docs and defaults. Deploying to fly.io was also easy, fly launch made it almost a no brainer. It generates a very good dockerfile and other relevant deployment related files. Heex is great to great to work with. Components do a good job separating small parts of the UI, encapsulating both their rendering and logic, allowing easy reuse.
I feel like I’ve got an OK understanding of latest liveview.
Things left to explore later: I did try out deploying to multiple regions on fly.io, which was easy, but I didn’t know how its routing works and whether you could reliably hit your closest server, so I reverted back to single server. Maybe a fun thing to do is to deploy a multi continent cluster and have the games shown globally. (oh, did I mention that you can enter others’ games and mess with help them)
Reviews and comments are welcome. Questions too!
Stay safe.
Trending in Discussions
Other Trending Topics
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
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
You should be able to use stateful components within
forand get granular updates.princemaple
princemaple
https://github.com/princemaple/mine_sweeper/blob/main/lib/mine_sweeper_web/live/session_live/cell_component.ex#L6-L9
^ This is my “workaround”. I hope it’s what you meant.
https://github.com/princemaple/mine_sweeper/blob/main/lib/mine_sweeper_web/live/session_live/show.html.heex#L22
^ I was hoping this would cause only individual cell gets the
updatecall, but whenever the cache busting map gets any update, the wholeforupdates (i.e. every single cell component gets the update call)qhwa
Awesome project, congrats!
I had the same question before and ended up using the following approach with a CDN test tool to confirm that it was routed to the nearest region.
Anycast is amazing.
princemaple
Thanks!
josefrichter
I wonder if every field being a separate genserver isn’t an overkill. But I assume it’s only for education purposes.
Now I’d be interested in opposite extreme where each game is just a single genserver with list state and simple css grid and you could squeeze all that fun in 10 LOC
princemaple
Yes. It’s intentionally over-engineered
Sebb
I’d like to see that 10loc version ..
josefrichter
Brilliant work! I really like how you did the neighbours function with filter, that’s shrewd
03juan
Late to the party but for funsies