add hasContext lifecycle function (#5690)

pull/5715/head
pushkin 4 years ago committed by GitHub
parent 0aa8cc1c9f
commit 01ead95cbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -178,6 +178,26 @@ Retrieves the context that belongs to the closest parent component with the spec
</script> </script>
``` ```
#### `hasContext`
```js
hasContext: boolean = hasContext(key: any)
```
---
Checks whether a given `key` has been set in the context of a parent component. Must be called during component initialisation.
```sv
<script>
import { hasContext } from 'svelte';
if (hasContext('answer')) {
// do something
}
</script>
```
#### `createEventDispatcher` #### `createEventDispatcher`
```js ```js

@ -54,6 +54,10 @@ export function getContext<T>(key): T {
return get_current_component().$$.context.get(key); return get_current_component().$$.context.get(key);
} }
export function hasContext(key): boolean {
return get_current_component().$$.context.has(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

Loading…
Cancel
Save