-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
live_json.ex
44 lines (39 loc) · 990 Bytes
/
live_json.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
defmodule ExampleWeb.LiveJson do
use ExampleWeb, :live_view
def render(assigns) do
~H"""
<div class="flex gap-10">
<div>
SSR:
<.svelte name="LiveJson" live_json_props={%{big_data_set: @ljbig_data_set}} socket={@socket} />
</div>
<div>
No SSR:
<.svelte name="LiveJson" live_json_props={%{big_data_set: @ljbig_data_set}} ssr={false} />
</div>
</div>
"""
end
def mount(_session, _params, socket) do
data =
for i <- 1..100_000,
into: %{} do
{i, Enum.random(1..1_000_000_000)}
end
{:ok, LiveJson.initialize(socket, "big_data_set", data)}
end
def handle_event("remove_element", _values, socket) do
random_key =
socket.assigns.ljbig_data_set
|> Map.keys()
|> Enum.random()
{
:noreply,
LiveJson.push_patch(
socket,
"big_data_set",
Map.delete(socket.assigns.ljbig_data_set, random_key)
)
}
end
end