Skip to content

Commit

Permalink
refactor: debug
Browse files Browse the repository at this point in the history
  • Loading branch information
istudyatuni committed Nov 10, 2023
1 parent 90549b5 commit 43ddace
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<Route path="/"><Highlights /></Route>
<Route path="/settings"><Settings /></Route>
<Route path="/debug">
<Lazy component={import('src/components/Debug.svelte')} />
<Lazy component={import('src/components/debug/Debug.svelte')} />
</Route>
</Route>
</Main>
Expand Down
48 changes: 0 additions & 48 deletions src/components/Debug.svelte

This file was deleted.

29 changes: 29 additions & 0 deletions src/components/debug/Debug.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script context="module">
import ObjectPrint from 'src/components/debug/ObjectPrint.svelte'
import { cache, log, settings } from 'src/stores'
</script>

<div class="wrapper">
<pre>Current version build time: {import.meta.env.VITE_VERSION}</pre>

<ObjectPrint name="LocalStorage.settings" object={$settings} />
<ObjectPrint name="LocalStorage.cache" object={$cache} />
<ObjectPrint name="API call log" object={$log.map((e) => decodeURI(e))} />
</div>

<style lang="scss">
.wrapper {
padding: 1em;
& :global(ul) {
list-style-type: '- ';
}
& :global(code) {
margin: 0;
height: 1em;
overflow-wrap: anywhere;
}
}
</style>
45 changes: 45 additions & 0 deletions src/components/debug/ObjectPrint.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<script>
/** Could be any object. Single values, arrays and objects are supported */
export let object = []
/** Leave empty to hide */
export let name = ''
$: object_is_array = is_array(object)
$: object_entries = Object.entries(object)
$: object_is_empty =
(object_is_array && object.length === 0) ||
(is_object(object) && object_entries.length === 0)
function is_object(o) {
return o instanceof Object
}
function is_array(o) {
return o instanceof Array
}
</script>

<div class:hidden={object_is_empty}>
<h4 class:hidden={name === ''}><pre>{name}</pre></h4>
<ul>
{#each object_entries as [key, value] (key)}
<li class:is-array={object_is_array}>
<code class:hidden={object_is_array}>{key}:</code>

{#if is_object(value)}
<svelte:self object={value} />
{:else}
<code>{JSON.stringify(value)}</code>
{/if}
</li>
{/each}
</ul>
</div>

<style>
.is-array {
list-style-type: circle;
}
.hidden {
display: none;
}
</style>

0 comments on commit 43ddace

Please sign in to comment.