aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorMaksymilian <maks@jopek.eu>2022-09-23 09:44:56 +0200
committerMaksymilian <maks@jopek.eu>2022-09-23 09:44:56 +0200
commit8886308c56223f04df535a065234414a6deb11ba (patch)
treebf432ab5e6a4ae754c4017bd9e0e663c25ccc055 /src/lib
downloadsvelte-pokeapi-8886308c56223f04df535a065234414a6deb11ba.tar.gz
svelte-pokeapi-8886308c56223f04df535a065234414a6deb11ba.tar.zst
svelte-pokeapi-8886308c56223f04df535a065234414a6deb11ba.zip
Initial commit, v1.0.0HEADmaster
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Counter.svelte12
-rw-r--r--src/lib/Tailwind.css3
-rw-r--r--src/lib/hmr-stores.js29
3 files changed, 44 insertions, 0 deletions
diff --git a/src/lib/Counter.svelte b/src/lib/Counter.svelte
new file mode 100644
index 0000000..e417505
--- /dev/null
+++ b/src/lib/Counter.svelte
@@ -0,0 +1,12 @@
+<script>
+ import { getStore } from './hmr-stores';
+ export let id;
+ const count = getStore(id, 0);
+ export const increment = () => {
+ $count += 1
+ };
+</script>
+
+<button class="px-8 py-4 w-52 text-red-500 bg-red-200 rounded-full" {id} on:click={increment}>
+ Clicks: {$count}
+</button> \ No newline at end of file
diff --git a/src/lib/Tailwind.css b/src/lib/Tailwind.css
new file mode 100644
index 0000000..bd6213e
--- /dev/null
+++ b/src/lib/Tailwind.css
@@ -0,0 +1,3 @@
+@tailwind base;
+@tailwind components;
+@tailwind utilities; \ No newline at end of file
diff --git a/src/lib/hmr-stores.js b/src/lib/hmr-stores.js
new file mode 100644
index 0000000..9cd6d0e
--- /dev/null
+++ b/src/lib/hmr-stores.js
@@ -0,0 +1,29 @@
+// Customized HMR-safe stores
+// Based off https://github.com/svitejs/svite/blob/ddec6b9/packages/playground/hmr/src/stores/hmr-stores.js
+import { writable } from 'svelte/store'
+
+/**
+ * @type { Record<string, import('svelte/store').Writable<any>> }
+ */
+let stores = {}
+
+/**
+ * @template T
+ * @param { string } id
+ * @param { T } initialValue
+ * @returns { import('svelte/store').Writable<T> }
+ */
+export function getStore(id, initialValue) {
+ return stores[id] || (stores[id] = writable(initialValue))
+}
+
+// preserve the store across HMR updates
+if (import.meta.hot) {
+ if (import.meta.hot.data.stores) {
+ stores = import.meta.hot.data.stores
+ }
+ import.meta.hot.accept()
+ import.meta.hot.dispose(() => {
+ import.meta.hot.data.stores = stores
+ })
+}