Created
February 5, 2019 22:50
-
-
Save jacwright/825b3fbe370a0da2c0dbadb38bed5cbe to your computer and use it in GitHub Desktop.
How do I update stores from reactive declaration updates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{#if match !== null} | |
<slot></slot> | |
{/if} | |
<script> | |
import { getHistory, matchPath, ROUTING_CONTEXT } from './index.js'; | |
import { writable } from 'svelte/store.js'; | |
import { setContext, onDestroy } from 'svelte'; | |
const history = getHistory(); | |
const matchStore = writable(null); | |
setContext(ROUTE_MATCH, matchStore); | |
export let path = ''; | |
export let exact = false; | |
export let strict = false; | |
let pathname = history.location.pathname; | |
let match; | |
// How do I update matchStore with this derived value? | |
$: match = matchPath(pathname, { path, exact, strict }); | |
const unlisten = history.listen(location => { | |
pathname = location.pathname; | |
}); | |
onDestroy(unlisten); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment