zhangzhen

zhangzhen

Has anybody tried to use Ash + Inertia.js together?

I want to use Ash as the backend and Inertia.js as web ui. has anyone done this before? Any suggestions are welcome.

Cheers,
Zhen Zhang

Most Liked

mbuhot

mbuhot

@mbuhot is giving a talk about Inertia.js at Elixir Sidney this week.

Youtube link for the meetup talk: https://www.youtube.com/watch?v=PEtGNztJaHg

I’ve been experimenting with InertiaJS and Phoenix for an implementation of the RealWorld Demo app.
GitHub - team-alembic/realworld-phoenix-inertia-react · GitHub (sorry for lack of docs!)

Overall it feels very simple, like good old MVC, but with React as your UI layer.

Having the page props immediately available so you never have loading states or error states from API requests is so nice.

The useForm hook is excellent, you submit your form data and let the server either respond with errors or redirect to a new page showing the result.

The backend is using Ash, so I followed @zachdaniel’s suggestion to implement the Inertia.Errors protocol which handles mapping errors from the domain layer onto form field errors.

The only issue I’ve run into was due to the way Inertia handles history navigation. By default it re-renders the page using the props originally provided when page was first loaded. In my case it caused inconsistency because parts of the page that would update in realtime by listening on a Phoenix Channel, but Inertia was unaware of those changes. I solved the problem by sending fresh state to the client after the Phoenix Channel joins.

To make it really nice I’d like to generate TypeScript types (maybe Zod schemas?) for any complex data types being rendered as props or sent over Phoenix Channels.

sbennett33

sbennett33

@mbuhot Thanks for the excellent talk! The repo you shared also helps answer a bunch of questions I had regarding simple things like flash messages and form handling. It’s going to save me a bunch of time trying to figure that stuff out on my own.

zachdaniel

zachdaniel

Creator of Ash

:cry: Ash does not define a JSON serializer like that automatically, primarily because it doesn’t really make a lot of sense to do given that different things can be loaded in different cases etc. However, if you must go that approach, you can derive a serializer if you like or use a tool like ash_json to derive one for you.

It is problematic that Inertia-phoenix integrates directly with Ecto in my opinion instead of providing behaviors that would let it work with anything. Likely integrating Ash with intertia-phoenix would necessitate making improvements to inertia-phoenix.

Wish I had a better answer for you :cry: Ultimately, this is the fundamental flaw that arises when libraries use Ecto.Schema as the integration point, instead of defining a behavior or protocol and making an Ecto.Schema implementation for it.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
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
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
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43657 311
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
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
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
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
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127536 1222
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement