Add deleteContext to Context API

Solves #6255
pull/6256/head
Henrik Giesel 5 years ago
parent a39fc8de72
commit 7efd6b5b5b

@ -55,7 +55,11 @@ export function getContext<T>(key): T {
} }
export function hasContext(key): boolean { export function hasContext(key): boolean {
return get_current_component().$$.context.has(key); return get_current_component().$$.context.has(key);
}
export function deleteContext(key): boolean {
return get_current_component().$$.context.delete(key);
} }
// TODO figure out if we still want to support // TODO figure out if we still want to support

@ -0,0 +1,8 @@
<script>
import { deleteContext } from 'svelte';
const deleted = deleteContext('test');
</script>
<div>{deleted}</div>
<slot />

@ -0,0 +1,8 @@
<script>
import { hasContext } from 'svelte';
const has = hasContext('test');
</script>
<div>{has}</div>
<slot />

@ -0,0 +1,7 @@
<script>
import { setContext } from 'svelte';
setContext('test', true);
</script>
<slot></slot>

@ -0,0 +1,7 @@
export default {
html: `
<div>true</div>
<div>false</div>
<div>false</div>
`
};

@ -0,0 +1,13 @@
<script>
import Nested from "./Nested.svelte";
import Delete from "./Delete.svelte";
import Leaf from "./Leaf.svelte";
</script>
<Nested>
<Delete>
<Leaf>
<Delete />
</Leaf>
</Delete>
</Nested>
Loading…
Cancel
Save