Skip to content

Instantly share code, notes, and snippets.

@gyenabubakar
Created August 16, 2022 17:44
Show Gist options
  • Save gyenabubakar/c26a07bbe2c2481b993f7b0891f71602 to your computer and use it in GitHub Desktop.
Save gyenabubakar/c26a07bbe2c2481b993f7b0891f71602 to your computer and use it in GitHub Desktop.
<script>
// since Child is wrapped inside VideoCallFunctionProvider,
// we can access the context value here
import { get } from '.VideoCallFunctionProvider.svelte';
const { triggerVideoCall } = get()
</script>
<button on:click={() => triggerVideoCall()}>
Call John Doe
</button>
<script>
import VideoCallFunctionProvider from '.VideoCallFunctionProvider.svelte';
import Child from 'Child.svelte'
</script>
<VideoCallFunctionProvider>
<!-- you'd wrap all dashboard stuff here -->
<Child />
</VideoCallFunctionProvider>
<script context="module">
export const KEY = 'video-call-func-ctx';
export const get = getContext(KEY);
</script>
<script>
import { setContext, getContext } from 'svelte';
function triggerVideoCall() {
// ... logic here
}
setContext(KEY, { triggerVideoCall });
</script>
<!-- You may put the video call markup here -->
<slot />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment