[feat] add deleteContext

pull/6647/head
Henrik Giesel 5 years ago
parent b1621d697d
commit 4e0e200b8f

@ -9,6 +9,7 @@ export {
getContext,
getAllContexts,
hasContext,
deleteContext,
tick,
createEventDispatcher,
SvelteComponentDev as SvelteComponent,

@ -59,7 +59,11 @@ export function getAllContexts<T extends Map<any, any> = Map<any, any>>(): T {
}
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

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

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

@ -0,0 +1,6 @@
<script>
import { setContext } from 'svelte';
setContext('test', true);
</script>
<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