mirror of https://github.com/sveltejs/svelte
fix: add `$set` and `$on` methods in legacy compat mode (#10642)
People could've done bind:this and called instance methods on the instance - a rare case, but not impossible. This shims $set and $on when in legacy compat mode. $destroy is never shimmed because you shouldn't manually destroy a component, ever, and there's no way to make that work in the new world. closes #10420pull/10654/head
parent
a4a789db4d
commit
749d3aa413
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"svelte": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: add `$set` and `$on` methods in legacy compat mode
|
@ -0,0 +1,17 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
compileOptions: {
|
||||||
|
legacy: {
|
||||||
|
componentApi: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
html: '<button>0</button>',
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const button = target.querySelector('button');
|
||||||
|
await button?.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(target.innerHTML, '<button>1</button>');
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,16 @@
|
|||||||
|
<script>
|
||||||
|
import Sub from './sub.svelte';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
let component;
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
component.$on('increment', (e) => {
|
||||||
|
count += e.detail;
|
||||||
|
component.$set({ count });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Sub bind:this={component} />
|
@ -0,0 +1,8 @@
|
|||||||
|
<script>
|
||||||
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
|
export let count = 0;
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button on:click={() => dispatch('increment', 1)}>{count}</button>
|
Loading…
Reference in new issue