Type scriptify 'Welcome' store

This commit is contained in:
Fred Boniface 2023-07-24 11:44:38 +01:00
parent 2ffa3510ee
commit d3cec6e15b
7 changed files with 19 additions and 12 deletions

View File

@ -1,4 +1,4 @@
<script>
<script lang="ts">
import Island from '$lib/islands/island.svelte';
export let variables = {
title: 'Uninitialised',

View File

@ -1,4 +1,4 @@
<script>
<script lang="ts">
import { fade } from 'svelte/transition';
export let variables = { title: '' };

View File

@ -1,4 +1,4 @@
<script>
<script lang="ts">
import { fade } from 'svelte/transition';
export let variables = { title: '' };

View File

@ -1,6 +1,13 @@
<script>
<script lang="ts">
import Island from '$lib/islands/island.svelte';
export let resultObject = {
interface resultObj {
results: boolean,
title: string,
resultLines: string[]
}
export let resultObject: resultObj = {
results: true,
title: '',
resultLines: []

View File

@ -1,3 +0,0 @@
export const version = '2023.7.1';
export const versionTag = 'beta.6';
export const showWelcome = true;

View File

@ -0,0 +1,3 @@
export const version: string = '2023.7.1';
export const versionTag: string = 'beta.6';
export const showWelcome: boolean = true;

View File

@ -1,10 +1,10 @@
import { writable } from 'svelte/store';
import { writable, type Writable } from 'svelte/store';
import { browser } from '$app/environment';
export const welcome = writable(fromLocalStorage('welcome', '0'));
toLocalStorage(welcome, 'welcome');
function fromLocalStorage(storageKey, fallback) {
function fromLocalStorage(storageKey: string, fallback: string) {
if (browser) {
const storedValue = localStorage.getItem(storageKey);
if (storedValue !== 'undefined') {
@ -14,9 +14,9 @@ function fromLocalStorage(storageKey, fallback) {
return fallback;
}
function toLocalStorage(store, storageKey) {
function toLocalStorage(store: Writable<any>, storageKey: string) {
if (browser) {
store.subscribe((value) => {
store.subscribe((value: string) => {
localStorage.setItem(storageKey, value);
});
}