Created
June 10, 2021 03:59
-
-
Save jonfriesen/d9fd58fd63b342d2fb5c2028cc250728 to your computer and use it in GitHub Desktop.
This file contains 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 component; | |
export let config; | |
export let items; | |
export let component_id; | |
let idIncrement = 0; | |
$items.forEach((item) => { | |
item.__id = idIncrement; | |
idIncrement++; | |
}); | |
function addItem() { | |
var l = $items.length; | |
$items[l] = { | |
__id: idIncrement, | |
}; | |
idIncrement++; | |
} | |
function removeItemFn(i) { | |
return () => { | |
$items = $items.filter(function (value, index, arr) { | |
if (value.__id != i) return value; | |
}); | |
}; | |
} | |
</script> | |
<ul> | |
{#each $items as item} | |
<li> | |
<svelte:component | |
this={component} | |
objAttributes={item} | |
config={config} | |
id={component_id} | |
removeFn={removeItemFn(item.__id)} | |
/> | |
</li> | |
{/each} | |
</ul> | |
<button on:click={addItem}> | |
<slot /> | |
</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment