Skip to content

Instantly share code, notes, and snippets.

@jacwright
Created February 5, 2019 22:50
Show Gist options
  • Save jacwright/825b3fbe370a0da2c0dbadb38bed5cbe to your computer and use it in GitHub Desktop.
Save jacwright/825b3fbe370a0da2c0dbadb38bed5cbe to your computer and use it in GitHub Desktop.
How do I update stores from reactive declaration updates
{#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