Add store example

This commit is contained in:
Wout De Puysseleir 2023-02-27 14:38:29 -08:00
parent da4979fdfb
commit f70dfe8941
No known key found for this signature in database
GPG key ID: 3DE9371B50FEC46A
5 changed files with 55 additions and 0 deletions

View file

@ -0,0 +1,7 @@
<script>
import store from './store'
</script>
<label>
<input type="checkbox" bind:checked={$store}/> {$store}
</label>

View file

@ -0,0 +1,7 @@
<script>
import store from './store'
</script>
<label>
<input type="checkbox" bind:checked={$store}/> {$store}
</label>

View file

@ -0,0 +1,14 @@
defmodule AppWeb.LiveSvelte1 do
use AppWeb, :live_view
def render(assigns) do
~H"""
<div class="mt-2 flex flex-col">
<%!-- Both work --%>
<.link navigate={~p"/svelte-2"}>svelte-2 with navigate</.link>
<.link patch={~p"/svelte-2"}>svelte-2 with patch</.link>
</div>
<.live_component module={LiveSvelte} name="StoreExample1" id="id"/>
"""
end
end

View file

@ -0,0 +1,14 @@
defmodule AppWeb.LiveSvelte2 do
use AppWeb, :live_view
def render(assigns) do
~H"""
<div class="mt-2 flex flex-col">
<%!-- Both work --%>
<.link navigate={~p"/svelte-1"}>svelte-1 with navigate</.link>
<.link patch={~p"/svelte-1"}>svelte-1 with patch</.link>
</div>
<.live_component module={LiveSvelte} name="StoreExample2" id="id" />
"""
end
end

13
examples/store/store.js Normal file
View file

@ -0,0 +1,13 @@
import {writable} from 'svelte/store'
function createStore() {
return writable(true)
}
function getStore() {
if (typeof window === 'undefined') return createStore()
window.store = window.store || createStore()
return window.store
}
export default store = getStore()