webdeb

webdeb

Hi, we have an NextJS Frontend Application which is basically React.

Now we would like to use a Phoenix App as a Service for some Live data. But we only need the JSON no HTML. Is Phoenix LiveView a good fit for this, or should we go with the low-level Phoenix Channels.

In comparison, I think that Channels is really low-level. On the other hand LiveView is very high-level and too HTML specific. IMHO something like LiveState would be a cool thing.

For example const { state, dispatch } = useLiveState() (React hooks)

Showing Posts 1 to 10

lud

lud

I would go with channels, yes. I don’t know if they are low level (I would say websockets are rather low-level, but not channels), but they are very easy to use, so low level or not they are a great tool if you want to push/stream data from the backend.

mpope

mpope

Channels could work. Have you considered using BERT instead of JSON? Sending data on the Elixir side would use :erlang.binary_to_term/1, which is fast. Then you could use Bert.js on the front end to decode into JS objects. Although it is admittedly a pretty dependency heavy lib.

hauleth

hauleth

BERT do not support maps, as it was created before OTP17 which added maps.

On the other hand I am working (when I find some time) on ERNIE which is “next gen” implementation of BERT.

mpope

mpope

Ah, hadn’t realized it was so out of date. Love the name.

webdeb

webdeb OP

My main concern is about the features that LiveView is offering besides HTML sync and event passing (which for my use-case aren’t important) but it seems that there are also other important features on top of plain Channels.

webdeb

webdeb OP

Thank you, I’ve considered BERT. But it does not make much sense when you have a heterogenous environment with different technologies.

lud

lud

To me it looks like this library has no dependencies at all (besides the test lib for dev).

https://github.com/ElixiumNetwork/bert-elixir/blob/master/package.json

methyl

methyl

Hey there.

I actually think it’s an idea with a lot of potential and use-cases that could be supported either in LiveView or as a separate library.

Being able to use whole React ecosystem while keeping the state in sync with your GenServers (or other abstraction) is something that we already experimented with. Take a look at this repo: GitHub - surferseo/livedata_todomvc · GitHub which is a proof of concept for the idea.

While the POC implementation is hideous, the API is really clean and powerful - check out livedata_todomvc/lib/phoenix_livedata_todomvc_web/live_data/todo_state.ex at master · surferseo/livedata_todomvc · GitHub and livedata_todomvc/assets/js/containers/TodoList.js at master · surferseo/livedata_todomvc · GitHub.

If you are interested in hearing more, check out this video https://www.youtube.com/watch?v=fvNy9bh8_vs where I talk a bit about motivations and the ugly internals.

Trying to make it play well with LiveView makes a lot of sense, as it lowers the barrier of entry to integrate it with existing JS codebases.

webdeb

webdeb OP

Cool! I think this is what I had in mind!

Update

@methyl
After watching your screencast. I am sure it’s exactly what I had in mind :slight_smile:

harmon25

harmon25

This looks is amazing, I would love to help polish LiveData and get it published on hex!

Exactly the kind of middle ground I am looking for - a lower level state abstraction than LiveView, but something a bit higher level than just channels.

I have had the exact mental model of redux <-phoenix-channel-> gen_server - and even made a similar proof of concept that leverages the gen_server state as the source of truth.

The addition of fast-json-patch is a great idea and is what morphdom does but with just the state, genius!

Any progress since the video and the code that you have posted?
If you started breaking it out into a new repo, I would be jumping on to contribute right away!

Where Next? Top

Trending in Questions Top

RSP87
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
nseaSeb
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
RemyXRenard
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
velrest
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
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
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
FlyingNoodle
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

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews