mirror of
https://github.com/woutdp/live_svelte
synced 2026-05-24 09:28:21 +00:00
Add store example
This commit is contained in:
parent
da4979fdfb
commit
f70dfe8941
5 changed files with 55 additions and 0 deletions
7
examples/store/StoreExample1.svelte
Normal file
7
examples/store/StoreExample1.svelte
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<script>
|
||||
import store from './store'
|
||||
</script>
|
||||
|
||||
<label>
|
||||
<input type="checkbox" bind:checked={$store}/> {$store}
|
||||
</label>
|
||||
7
examples/store/StoreExample2.svelte
Normal file
7
examples/store/StoreExample2.svelte
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<script>
|
||||
import store from './store'
|
||||
</script>
|
||||
|
||||
<label>
|
||||
<input type="checkbox" bind:checked={$store}/> {$store}
|
||||
</label>
|
||||
14
examples/store/live_svelte_1.ex
Normal file
14
examples/store/live_svelte_1.ex
Normal 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
|
||||
14
examples/store/live_svelte_2.ex
Normal file
14
examples/store/live_svelte_2.ex
Normal 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
13
examples/store/store.js
Normal 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()
|
||||
Loading…
Reference in a new issue