diff --git a/example_project/assets/svelte/LogList.svelte b/example_project/assets/svelte/LogList.svelte index 9207505..fc7d8e1 100644 --- a/example_project/assets/svelte/LogList.svelte +++ b/example_project/assets/svelte/LogList.svelte @@ -3,14 +3,14 @@ export let pushEvent export let items = [] - let newItemName + let body let i = 1 let showItems = true function addItem() { - if (!newItemName) return - pushEvent("add_item", {name: newItemName}) - newItemName = "" + if (!body) return + pushEvent("add_item", {body}) + body = "" } @@ -27,7 +27,7 @@
- + @@ -40,7 +40,7 @@ {#each items.slice(0, i) as item (item.id)}
- {item.id}: {item.name} + {item.id}: {item.body}
{/each} diff --git a/example_project/lib/example_web/live/live_log_list.ex b/example_project/lib/example_web/live/live_log_list.ex index cdaf16b..a88c9e9 100644 --- a/example_project/lib/example_web/live/live_log_list.ex +++ b/example_project/lib/example_web/live/live_log_list.ex @@ -12,8 +12,8 @@ defmodule ExampleWeb.LiveExample4 do {:ok, assign(socket, :items, [])} end - def handle_event("add_item", %{"name" => name}, socket) do - {:noreply, assign(socket, :items, add_log(socket, name))} + def handle_event("add_item", %{"body" => body}, socket) do + {:noreply, assign(socket, :items, add_log(socket, body))} end def handle_info(:tick, socket) do @@ -25,6 +25,6 @@ defmodule ExampleWeb.LiveExample4 do end defp add_log(socket, body) do - [%{id: System.unique_integer([:positive]), name: body} | socket.assigns.items] + [%{id: System.unique_integer([:positive]), body: body} | socket.assigns.items] end end