-
Notifications
You must be signed in to change notification settings - Fork 19
[Landing] llv examples animation #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3b1afc0
edcb0a2
0c70aff
2403a16
7b341cd
12ab95d
66c6569
5abc56f
d353f84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,7 +124,7 @@ | |
| font-size: 15px; | ||
| } | ||
|
|
||
| .title { | ||
| h1 { | ||
| padding: 30px 25px; | ||
| font-size: 30px; | ||
| font-weight: bold; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| defmodule FormDemoLocalPresentation do | ||
| use LocalLiveView | ||
|
|
||
| defdelegate render(assigns), to: FormDemoLocal | ||
|
|
||
| def mount(params, session, socket) do | ||
| result = FormDemoLocal.mount(params, session, socket) | ||
| {:ok, new_socket} = result | ||
|
|
||
| Popcorn.Wasm.send_event("llv_presentation", %{ | ||
| block: nil, | ||
| event: "mount", | ||
| assigns: presentation_assigns(new_socket) | ||
| }) | ||
|
|
||
| result | ||
| end | ||
|
|
||
| def handle_event(event, params, socket) | ||
| when event in ~w(validate save generate_random) do | ||
| # The UI socket lags behind the real state during animation; apply pending | ||
| # assigns so the event handler sees up-to-date data. | ||
| effective_socket = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is weird:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a workaround to keep track of the previous event, allowing the animation to continue when the user spams events and executing the animation with the last pending update value |
||
| case socket.assigns[:pending_cur] do | ||
| nil -> socket | ||
| pending -> assign(socket, Map.to_list(pending)) | ||
| end | ||
|
|
||
| {:noreply, updated} = FormDemoLocal.handle_event(event, params, effective_socket) | ||
|
|
||
| Popcorn.Wasm.send_event("llv_presentation", %{ | ||
| block: event, | ||
| event: event, | ||
| assigns: presentation_assigns(updated) | ||
| }) | ||
|
|
||
| new_pending = %{ | ||
| form: updated.assigns.form, | ||
| disabled: updated.assigns.disabled, | ||
| users: updated.assigns.users | ||
| } | ||
|
|
||
| {:noreply, | ||
| socket | ||
| |> assign(:pending_prev, socket.assigns[:pending_cur]) | ||
| |> assign(:pending_cur, new_pending)} | ||
| end | ||
|
|
||
| def handle_info({:js_push, "llv_ack", _}, socket) do | ||
| case {socket.assigns[:pending_prev], socket.assigns[:pending_cur]} do | ||
| {%{form: form, disabled: disabled, users: users}, _} -> | ||
| {:noreply, assign(socket, form: form, disabled: disabled, users: users, pending_prev: nil)} | ||
|
|
||
| {nil, %{form: form, disabled: disabled, users: users}} -> | ||
| {:noreply, assign(socket, form: form, disabled: disabled, users: users, pending_cur: nil)} | ||
|
|
||
| _ -> | ||
| {:noreply, socket} | ||
| end | ||
| end | ||
|
|
||
| def handle_event(event, params, socket) do | ||
| FormDemoLocal.handle_event(event, params, socket) | ||
| end | ||
|
|
||
| defp presentation_assigns(socket) do | ||
| assigns = socket.assigns | ||
| form_params = assigns.form.params | ||
|
|
||
| %{ | ||
| username: Map.get(form_params, "username", ""), | ||
| email: Map.get(form_params, "email", ""), | ||
| disabled: assigns.disabled, | ||
| users: length(assigns.users) | ||
| } | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ defmodule Local.MixProject do | |
| version: "0.1.0", | ||
| elixir: "~> 1.17", | ||
| start_permanent: Mix.env() == :prod, | ||
| elixirc_paths: elixirc_paths(), | ||
| deps: deps(), | ||
| compilers: Mix.compilers(), | ||
| aliases: aliases() | ||
|
|
@@ -17,6 +18,17 @@ defmodule Local.MixProject do | |
| [default_target: :wasm] | ||
| end | ||
|
|
||
| # lib_landing contains presentation wrappers that emit WASM events for the | ||
| # landing page animation demos. They are compiled only when building for that | ||
| # context so normal development builds stay unaffected. | ||
| defp elixirc_paths do | ||
| if System.get_env("LLV_LANDING_PATCH") == "true" do | ||
| ["lib", "lib_landing"] | ||
| else | ||
| ["lib"] | ||
| end | ||
|
Comment on lines
+25
to
+29
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To separate landing page versions that handle event modification from those kept as the normal example |
||
| end | ||
|
|
||
| def application do | ||
| [ | ||
| extra_applications: [:logger], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| defmodule ThermostatLivePresentation do | ||
| use LocalLiveView | ||
|
|
||
| defdelegate render(assigns), to: ThermostatLive | ||
|
|
||
| def mount(params, session, socket) do | ||
| result = ThermostatLive.mount(params, session, socket) | ||
| {:ok, new_socket} = result | ||
|
|
||
| Popcorn.Wasm.send_event("llv_presentation", %{ | ||
| block: nil, | ||
| event: "mount", | ||
| assigns: presentation_assigns(new_socket) | ||
| }) | ||
|
|
||
| result | ||
| end | ||
|
|
||
| def handle_event(event, params, socket) | ||
| when event in ~w(inc_temperature dec_temperature) do | ||
| # The UI socket lags behind the real state during animation; apply pending | ||
| # assigns so the event handler sees up-to-date data. | ||
| effective_socket = | ||
| case socket.assigns[:pending_cur] do | ||
| nil -> socket | ||
| pending -> assign(socket, Map.to_list(pending)) | ||
| end | ||
|
|
||
| {:noreply, updated} = ThermostatLive.handle_event(event, params, effective_socket) | ||
|
|
||
| Popcorn.Wasm.send_event("llv_presentation", %{ | ||
| block: event, | ||
| event: event, | ||
| assigns: presentation_assigns(updated) | ||
| }) | ||
|
|
||
| new_pending = %{ | ||
| temperature: updated.assigns.temperature, | ||
| country: updated.assigns.country | ||
| } | ||
|
|
||
| {:noreply, | ||
| socket | ||
| |> assign(:pending_prev, socket.assigns[:pending_cur]) | ||
| |> assign(:pending_cur, new_pending)} | ||
| end | ||
|
|
||
| def handle_info({:js_push, "llv_ack", _}, socket) do | ||
| case {socket.assigns[:pending_prev], socket.assigns[:pending_cur]} do | ||
| {%{temperature: t, country: c}, _} -> | ||
| {:noreply, assign(socket, temperature: t, country: c, pending_prev: nil)} | ||
|
|
||
| {nil, %{temperature: t, country: c}} -> | ||
| {:noreply, assign(socket, temperature: t, country: c, pending_cur: nil)} | ||
|
|
||
| _ -> | ||
| {:noreply, socket} | ||
| end | ||
| end | ||
|
|
||
| def handle_event(event, params, socket) do | ||
| ThermostatLive.handle_event(event, params, socket) | ||
| end | ||
|
|
||
| defp presentation_assigns(socket) do | ||
| %{ | ||
| temperature: socket.assigns.temperature, | ||
| country: socket.assigns.country | ||
| } | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to leave a comment why we need it so we can remove it later if it stops being necessary.