PhoenixVapor.Reactive (PhoenixVapor v0.6.1)

Copy Markdown View Source

Server-side Vue reactivity via QuickBEAM.

Use via: use PhoenixVapor, file: "X.vue", runtime: :reactive

Compiles <script setup> + <template> from a .vue file into a fully functional LiveView with auto-generated mount, render, and event handlers.

A persistent runtime (QuickBEAM with Vue's reactivity) is started per LiveView process. ref() values become reactive state, computed() auto-update when deps change, and functions execute in the persistent JS context — state survives across events.

Usage

defmodule MyAppWeb.CounterLive do
  use MyAppWeb, :live_view
  use PhoenixVapor, file: "Counter.vue", runtime: :reactive
end

Given Counter.vue:

<script setup>
import { ref, computed } from "vue"

const count = ref(0)
const doubled = computed(() => count * 2)

function increment() { count++ }
</script>

<template>
  <p>{{ count }} × 2 = {{ doubled }}</p>
  <button @click="increment">+</button>
</template>

This generates:

  • mount/3 — starts a Runtime with refs, computeds, and functions
  • render/1 — renders the template, compiled from Vize's split, with the runtime's state
  • handle_event/3 — calls the function in the runtime, assigns new state

Summary

Functions

Picks the URL params named by keys and returns them as assigns.

Converts the state the component's runtime returns into assigns.

Functions

param_assigns(params, keys)

@spec param_assigns(map() | :not_mounted_at_router, [atom()]) :: map()

Picks the URL params named by keys and returns them as assigns.

Generated mount/3 callbacks pass the assign keys their template reads, so a param never creates an atom.

state_to_assigns(state, keys)

@spec state_to_assigns(map(), [atom()]) :: map()

Converts the state the component's runtime returns into assigns.

keys are the ref and computed names declared in the component, as atoms created when it compiled.