mirror of https://github.com/sveltejs/svelte
[feat] get all contexts (#6528)
* get all contexts * docs * explicit return type * allow specifying return type through generic parameter * Update site/content/docs/03-run-time.md Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>pull/6560/head
parent
f6a9804275
commit
222a9dd2c6
@ -0,0 +1,9 @@
|
|||||||
|
<script>
|
||||||
|
import { getAllContexts } from 'svelte';
|
||||||
|
|
||||||
|
const context = getAllContexts();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#each [...context.keys()] as key}
|
||||||
|
<div>{key}: {context.get(key)}</div>
|
||||||
|
{/each}
|
@ -0,0 +1,8 @@
|
|||||||
|
<script>
|
||||||
|
import { setContext } from 'svelte';
|
||||||
|
setContext('a', 1);
|
||||||
|
setContext('b', 2);
|
||||||
|
setContext('c', 3);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<slot></slot>
|
@ -0,0 +1,7 @@
|
|||||||
|
export default {
|
||||||
|
html: `
|
||||||
|
<div>a: 1</div>
|
||||||
|
<div>b: 2</div>
|
||||||
|
<div>c: 3</div>
|
||||||
|
`
|
||||||
|
};
|
@ -0,0 +1,8 @@
|
|||||||
|
<script>
|
||||||
|
import Nested from './Nested.svelte';
|
||||||
|
import Leaf from './Leaf.svelte';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Nested>
|
||||||
|
<Leaf />
|
||||||
|
</Nested>
|
Loading…
Reference in new issue