mirror of https://github.com/sveltejs/svelte
always-create-root-context
parent
16fec7207a
commit
4c8f151af8
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': minor
|
||||
---
|
||||
|
||||
feat: allow use of createContext when instantiating components programmatically
|
||||
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
import { get } from './main.svelte';
|
||||
|
||||
const message = get();
|
||||
</script>
|
||||
|
||||
<h1>{message}</h1>
|
||||
@ -0,0 +1,8 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
ssrHtml: `<div></div>`,
|
||||
html: `<div><h1>hello</h1></div>`,
|
||||
|
||||
test() {}
|
||||
});
|
||||
@ -0,0 +1,20 @@
|
||||
<script module>
|
||||
import { createContext, mount } from 'svelte';
|
||||
import Child from './Child.svelte';
|
||||
|
||||
/** @type {ReturnType<typeof createContext<string>>} */
|
||||
const [get, set] = createContext();
|
||||
|
||||
export { get };
|
||||
|
||||
function Wrapper(Component) {
|
||||
return (...args) => {
|
||||
set('hello');
|
||||
return Component(...args);
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<div {@attach (target) => {
|
||||
mount(Wrapper(Child), { target });
|
||||
}}></div>
|
||||
Loading…
Reference in new issue