Created
February 14, 2022 08:19
-
-
Save bombless/671360528f80b48aca24fb2c66ad9f8d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
export let value = [1, [2, [3]]]; | |
function extend(idx) { | |
return () => { | |
view[idx] = value[idx]; | |
}; | |
} | |
function strip(idx) { | |
return () => { | |
console.log('strip', view[idx]); | |
view[idx] = extend(idx); | |
view = view; | |
value = value; | |
console.log('strip', view[idx]); | |
}; | |
} | |
let view = value.map((x, idx) => x instanceof Array ? extend(idx) : x); | |
</script> | |
<content> | |
{#each view as item, idx} | |
{#if item.call} | |
<i on:click={item}>folder</i> | |
{:else if item.slice} | |
<i on:click={strip(idx)}>+</i> | |
<svelte:self value={item}></svelte:self> | |
{:else} | |
<p> | |
{item} | |
</p> | |
{/if} | |
{/each} | |
</content> | |
<style> | |
p{user-select: none;} | |
i{cursor: pointer; user-select: none; display: block;} | |
content{padding-left: 3em;display:inline-block;} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://svelte.dev/repl/91dbfc7f9eec4c37971c6981a374d955?version=3.46.4