mirror of https://github.com/sveltejs/svelte
feat: allow use of createContext when instantiating components programmatically (#17575)
* feat: allow use of createContext when instantiating components programmatically * docspull/17628/head
parent
f05f946fea
commit
fcbd3e325a
@ -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