mirror of https://github.com/sveltejs/svelte
[fix] prefer context from constructor options (#6759)
parent
cfc880bb31
commit
67b53bfe6d
@ -0,0 +1,6 @@
|
|||||||
|
<script>
|
||||||
|
import { getContext } from 'svelte';
|
||||||
|
const value = getContext('foo');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>Value in child component: {value}</div>
|
@ -0,0 +1,6 @@
|
|||||||
|
export default {
|
||||||
|
skip_if_ssr: true,
|
||||||
|
html: `
|
||||||
|
<div><div>Value in child component: undefined</div></div>
|
||||||
|
`
|
||||||
|
};
|
@ -0,0 +1,15 @@
|
|||||||
|
<script>
|
||||||
|
import { setContext } from 'svelte';
|
||||||
|
import ChildComponent from './ChildComponent.svelte';
|
||||||
|
|
||||||
|
setContext('foo', true);
|
||||||
|
|
||||||
|
function render(node) {
|
||||||
|
new ChildComponent({
|
||||||
|
target: node,
|
||||||
|
context: new Map()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div use:render />
|
@ -0,0 +1,6 @@
|
|||||||
|
<script>
|
||||||
|
import { getContext } from 'svelte';
|
||||||
|
const value = getContext('foo');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>Value in child component: {value}</div>
|
@ -0,0 +1 @@
|
|||||||
|
<div><div>Value in child component: undefined</div></div>
|
@ -0,0 +1,10 @@
|
|||||||
|
<script>
|
||||||
|
import { setContext } from 'svelte';
|
||||||
|
import ChildComponent from './ChildComponent.svelte';
|
||||||
|
|
||||||
|
setContext('foo', true);
|
||||||
|
|
||||||
|
const content = ChildComponent.render({}, { context: new Map() }).html;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>{@html content}</div>
|
Loading…
Reference in new issue