2
votes

I'm looking into building an application with a lot of real-time features.

I've quickly skimmed over channels. Does Phoenix have some magic code that will hide the DOM-updating logic from me? A package maybe? I'm not interested in writing JavaScript code to update/manipulate the DOM. It seems reasonable to expect that Phoenix can re-render the template server-side and send the changed DOM over a channel - is that not possible?

If the above exists, maybe there exists something that can translate Phoenix's templates to client-side JavaScript views which can take the same variables that a Phoenix templates takes and then render the view? This way, Phoenix doesn't have to send the whole DOM over, but just the variables.

I'm asking because I want to write 100% Elixir code and the above 2 ideas seem reasonable ways of doing just that.

4

4 Answers

5
votes

Drab may be the library you're looking for.

Drab is the extension library to Phoenix Framework for providing an access to the browser's User Interface (DOM objects) from the server side. The main advantage is to eliminate necessity of writing two applications: one for the client-side, and one for the backend. All the UI control may be now done in the backend, eliminating JS and AJAX.

1
votes

In the meantime, Phoenix LiveView has come out, which does exactly what I asked for in the original question :)

0
votes

Javascript code has to be executed at some point if you want to change the DOM after the initial page load. But that doesn't mean you have to write that code with javascript. You might want to checkout Elixirscript. It lets you write Elixir code that compiles down to Javascript.

0
votes

Step - by - step:

Does Phoenix have some magic code that will hide the DOM-updating logic from me? A package maybe?

No

I'm not interested in writing JavaScript code to update/manipulate the DOM. It seems reasonable to expect that Phoenix can re-render the template server-side and send the changed DOM over a channel - is that not possible?

No this is not reasonable at all, Phoenix is a server-side framework. phoenix.js is just a communication layer for js applications

If the above exists, maybe there exists something that can translate Phoenix's templates to client-side JavaScript views which can take the same variables that a Phoenix templates takes and then render the view? This way, Phoenix doesn't have to send the whole DOM over, but just the variables.

Look you have some basic misunderstandings of how real-time / server-client side communications works and such thing.

I have a feeling, that you have a Meteor background, where all that stuff just happens magically. If so, you should stay with Meteor, because if you try to apply the same concepts to Elixir/Phoenix it will gonna scale shame shitty like Meteor (sorry for that trolling)

I'm asking because I want to write 100% Elixir code and the above 2 ideas seem reasonable ways of doing just that.

Ok, but it is not possible.