/* App.svelte generated by Svelte v4.2.19 */
import {
SvelteComponent,
check_outros,
create_component,
destroy_component,
destroy_each,
detach,
element,
empty,
ensure_array_like,
group_outros,
init,
insert,
listen,
mount_component,
safe_not_equal,
space,
transition_in,
transition_out
} from "svelte/internal";
import "svelte/internal/disclose-version";
import Thing from './Thing.svelte';
function get_each_context(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[2] = list[i];
return child_ctx;
}
// (19:0) {#each things as thing}
function create_each_block(ctx) {
let thing_1;
let current;
thing_1 = new Thing({ props: { name: /*thing*/ ctx[2].name } });
return {
c() {
create_component(thing_1.$$.fragment);
},
m(target, anchor) {
mount_component(thing_1, target, anchor);
current = true;
},
p(ctx, dirty) {
const thing_1_changes = {};
if (dirty & /*things*/ 1) thing_1_changes.name = /*thing*/ ctx[2].name;
thing_1.$set(thing_1_changes);
},
i(local) {
if (current) return;
transition_in(thing_1.$$.fragment, local);
current = true;
},
o(local) {
transition_out(thing_1.$$.fragment, local);
current = false;
},
d(detaching) {
destroy_component(thing_1, detaching);
}
};
}
function create_fragment(ctx) {
let button;
let t1;
let each_1_anchor;
let current;
let mounted;
let dispose;
let each_value = ensure_array_like(/*things*/ ctx[0]);
let each_blocks = [];
for (let i = 0; i < each_value.length; i += 1) {
each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i));
}
const out = i => transition_out(each_blocks[i], 1, 1, () => {
each_blocks[i] = null;
});
return {
c() {
button = element("button");
button.textContent = "Remove first thing";
t1 = space();
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
each_1_anchor = empty();
},
m(target, anchor) {
insert(target, button, anchor);
insert(target, t1, anchor);
for (let i = 0; i < each_blocks.length; i += 1) {
if (each_blocks[i]) {
each_blocks[i].m(target, anchor);
}
}
insert(target, each_1_anchor, anchor);
current = true;
if (!mounted) {
dispose = listen(button, "click", /*handleClick*/ ctx[1]);
mounted = true;
}
},
p(ctx, [dirty]) {
if (dirty & /*things*/ 1) {
each_value = ensure_array_like(/*things*/ ctx[0]);
let i;
for (i = 0; i < each_value.length; i += 1) {
const child_ctx = get_each_context(ctx, each_value, i);
if (each_blocks[i]) {
each_blocks[i].p(child_ctx, dirty);
transition_in(each_blocks[i], 1);
} else {
each_blocks[i] = create_each_block(child_ctx);
each_blocks[i].c();
transition_in(each_blocks[i], 1);
each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor);
}
}
group_outros();
for (i = each_value.length; i < each_blocks.length; i += 1) {
out(i);
}
check_outros();
}
},
i(local) {
if (current) return;
for (let i = 0; i < each_value.length; i += 1) {
transition_in(each_blocks[i]);
}
current = true;
},
o(local) {
each_blocks = each_blocks.filter(Boolean);
for (let i = 0; i < each_blocks.length; i += 1) {
transition_out(each_blocks[i]);
}
current = false;
},
d(detaching) {
if (detaching) {
detach(button);
detach(t1);
detach(each_1_anchor);
}
destroy_each(each_blocks, detaching);
mounted = false;
dispose();
}
};
}
function instance($$self, $$props, $$invalidate) {
let things = [
{ id: 1, name: 'apple' },
{ id: 2, name: 'banana' },
{ id: 3, name: 'carrot' },
{ id: 4, name: 'doughnut' },
{ id: 5, name: 'egg' }
];
function handleClick() {
$$invalidate(0, things = things.slice(1));
}
return [things, handleClick];
}
class App extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance, create_fragment, safe_not_equal, {});
}
}
export default App;