mirror of https://github.com/sveltejs/svelte
parent
f5102013af
commit
b80d9bd654
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
fix: wire up `events` in `mount` correctly and fix its types
|
@ -0,0 +1,21 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<button>toggle</button><div></div>`,
|
||||
async test({ assert, target }) {
|
||||
const button = target.querySelector('button');
|
||||
|
||||
await button?.click();
|
||||
assert.htmlEqual(target.innerHTML, `<button>toggle</button><div><button>0</button></div>`);
|
||||
|
||||
const inner_button = target.querySelector('div')?.querySelector('button');
|
||||
|
||||
inner_button?.click();
|
||||
await tick();
|
||||
assert.htmlEqual(target.innerHTML, `<button>toggle</button><div><button>2</button></div>`);
|
||||
|
||||
await button?.click();
|
||||
assert.htmlEqual(target.innerHTML, `<button>toggle</button><div></div>`);
|
||||
}
|
||||
});
|
@ -0,0 +1,11 @@
|
||||
<script>
|
||||
import { createEventDispatcher, getContext } from "svelte";
|
||||
|
||||
let { count } = $props();
|
||||
const multiply = getContext('multiply');
|
||||
|
||||
// Use legacy createEventDispatcher here to test that `events` property in `mount` works
|
||||
const dispatch = createEventDispatcher();
|
||||
</script>
|
||||
|
||||
<button onclick={() => dispatch('update', count + 1 * multiply)}>{count}</button>
|
@ -0,0 +1,20 @@
|
||||
<script>
|
||||
import { mount, unmount } from 'svelte';
|
||||
import Inner from './inner.svelte';
|
||||
|
||||
let el;
|
||||
let component;
|
||||
let props = $state({count: 0});
|
||||
|
||||
function toggle() {
|
||||
if (component) {
|
||||
unmount(component);
|
||||
component = null;
|
||||
} else {
|
||||
component = mount(Inner, { target: el, props, context: new Map([['multiply', 2]]), events: { update: (e) => props.count = e.detail } });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick={toggle}>toggle</button>
|
||||
<div bind:this={el}></div>
|
Loading…
Reference in new issue