coen.bakker

coen.bakker

Daydreaming about Svelte-like syntax inside render functions

I appreciate being able to use AlpineJS inside my render functions, but often I catch myself wishing I could use Svelte syntax instead. And have the compiler turn the Svelte code to plain JS.

What do you think: how messy would that implementation get?

For example:

defmodule AppWeb.PageLive
  use Surface.LiveView

  def render(assigns) do
    ~F"""
      <div id="page">
        {#if @value and count == 0}
          <SurfaceComponent id="surface-component"/>
        {#else}
          <AnotherSurfaceComponent id="another-surface-component"/>
        {/if}

        <button on:click={handleClick}>
          Clicked {count} {count === 1 ? 'time' : 'times'}
        </button>
      </div>

    <script>
      let count = 0

      function handleClick() {
        count += 1
      }
    </script>
    """
  end
end

I am well aware that there are syntax conflicts right from the get-go between Svelte/JavaScript and Elixir/Phoenix/Surface. I reckon the best way of integrating Svelte is… not doing so. But rather extending Surface functionality into the JavaScript domain, or building a compiler layer on top of Phoenix from scratch – and being ‘inspired’ by Svelte.

Would it be a relieve to have such a tool… or not?

First Post!

cmo

cmo

{#if @value and count == 0}

How does the server rendered page get the count value from the front-end?

Most Liked

LostKobrakai

LostKobrakai

What I considered, but never managed to try, with svelte would be using svelte client side only and use a custom svelte store to communicate to the backend, which today could possibly even be something like live_json, though plain channels might work as well.

Last Post!

coen.bakker

coen.bakker

Interesting. Have an idea what it might be, but what do you have in mind? In general terms how would you utilize WA?

Where Next?

Popular in Discussions Top

New
jesse
Hi everyone, I hesitated to post this here because I don’t want you to think I’m spamming, but I’ve been working on a Platform-as-a-Serv...
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
AstonJ
If so I (and hopefully others!) might have some tips for you :slight_smile: But first, please say which area you’re finding most challen...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
Fl4m3Ph03n1x
Background A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell. I...
New
matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
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
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement