Skip to content

Instantly share code, notes, and snippets.

@jonfriesen
Created June 10, 2021 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonfriesen/d9fd58fd63b342d2fb5c2028cc250728 to your computer and use it in GitHub Desktop.
Save jonfriesen/d9fd58fd63b342d2fb5c2028cc250728 to your computer and use it in GitHub Desktop.
<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