mirror of https://github.com/sveltejs/svelte
parent
868e3fa56e
commit
c60e30d7de
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: allow usage of `$props.id` everywhere if invoked within a component script
|
@ -0,0 +1,6 @@
|
|||||||
|
<script>
|
||||||
|
import { get_id } from "./get_id.svelte.js";
|
||||||
|
let id = get_id();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>{id}</p>
|
@ -0,0 +1,27 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
test({ assert, target, variant }) {
|
||||||
|
const ps = [...target.querySelectorAll('p')].map((p) => p.innerHTML);
|
||||||
|
const unique = new Set(ps);
|
||||||
|
assert.equal(ps.length, unique.size);
|
||||||
|
|
||||||
|
if (variant === 'hydrate') {
|
||||||
|
const start = ps.map((p) => p.substring(0, 1));
|
||||||
|
assert.deepEqual(start, ['s', 's', 's', 's']);
|
||||||
|
}
|
||||||
|
|
||||||
|
let button = target.querySelector('button');
|
||||||
|
flushSync(() => button?.click());
|
||||||
|
|
||||||
|
const ps_after = [...target.querySelectorAll('p')].map((p) => p.innerHTML);
|
||||||
|
const unique_after = new Set(ps_after);
|
||||||
|
assert.equal(ps_after.length, unique_after.size);
|
||||||
|
|
||||||
|
if (variant === 'hydrate') {
|
||||||
|
const start = ps_after.map((p) => p.substring(0, 1));
|
||||||
|
assert.deepEqual(start, ['s', 's', 's', 's', 'c']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,3 @@
|
|||||||
|
export function get_id() {
|
||||||
|
return $props.id();
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
<script>
|
||||||
|
import { get_id } from "./get_id.svelte.js";
|
||||||
|
import Child from './Child.svelte';
|
||||||
|
|
||||||
|
let id = get_id();
|
||||||
|
|
||||||
|
let show = $state(false);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => show = !show}>toggle</button>
|
||||||
|
|
||||||
|
<p>{id}</p>
|
||||||
|
|
||||||
|
<Child />
|
||||||
|
<Child />
|
||||||
|
<Child />
|
||||||
|
|
||||||
|
{#if show}
|
||||||
|
<Child />
|
||||||
|
{/if}
|
Loading…
Reference in new issue