[feat] add deleteContext

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

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

@ -62,6 +62,10 @@ 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
// shorthand events, or if we want to implement // shorthand events, or if we want to implement
// a real bubbling mechanism // a real bubbling mechanism

@ -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