Skip to content

Instantly share code, notes, and snippets.

@bombless
Created February 14, 2022 08:19
Show Gist options
  • Save bombless/671360528f80b48aca24fb2c66ad9f8d to your computer and use it in GitHub Desktop.
Save bombless/671360528f80b48aca24fb2c66ad9f8d to your computer and use it in GitHub Desktop.
<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