-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
2,498 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
dist | ||
cmp/aors.js |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script context="module"> | ||
let count = 1; | ||
</script> | ||
<script> | ||
import {getContext,setContext,onMount} from 'svelte'; | ||
import {routes,current} from './../dist/aors_lib'; | ||
const routeId = count++; | ||
let exact = true; | ||
let subroutes = []; | ||
export let path = '/'; | ||
//export let fallback = false; | ||
const parentRoute = getContext('ROUTE:data'); | ||
let base = path==='/' ? '' : path; | ||
if(parentRoute){ | ||
base = parentRoute.base+base; | ||
onMount(_ => parentRoute.mount(routeId)); | ||
} | ||
setContext('ROUTE:data',{base,mount: id => { | ||
subroutes.push(id) | ||
subroutes = subroutes; | ||
console.log('abc',subroutes); | ||
return _ => subroutes = subroutes.filter(e=>e!==id); | ||
}}); | ||
$: console.log(base,subroutes); | ||
// $: routes.register(base,routeId,exact,fallback); | ||
</script> | ||
|
||
{#if $current[routeId]} | ||
<slot></slot> | ||
{/if} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<script> | ||
import {current_component} from 'svelte/internal'; | ||
import {getContext,setContext,afterUpdate} from 'svelte'; | ||
import {url,getPathData,formatPath} from './../dist/aors_lib'; | ||
export let path = '/*'; | ||
export let fallback = false; | ||
let route = null; | ||
let show_content = false; | ||
let fallback_cb = null; | ||
let childs = []; | ||
let exact = fallback || !path.endsWith('/*'); | ||
path = formatPath(path); | ||
const ctx = getContext('ROUTER:context'); | ||
if(ctx) path = ctx.base+path; | ||
if(ctx && fallback) ctx.regFB( _ => show_content=true ); | ||
const show_fallback = _ => fallback_cb ? fallback_cb() : ctx ? ctx.showFB() : null; | ||
setContext('ROUTER:context',{ | ||
base: path, | ||
nochilds: exact, | ||
child: (show,path) => show ? childs.push(path) : childs=childs.filter( e => e!==path ), | ||
regFB: func => fallback_cb = func, | ||
showFB: show_fallback | ||
}); | ||
$: route = getPathData(path,$url.path); | ||
$: show_content = fallback ? false : !!route && ( (exact && route.exact) || !exact ); | ||
$: if(ctx && !fallback) ctx.child(show_content,path); | ||
afterUpdate( _ => (route && !route.exact && !exact && childs.length === 0) ? show_fallback() : null); | ||
</script> | ||
|
||
{#if show_content} | ||
<slot></slot> | ||
{/if} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script> | ||
import {getContext,setContext,onMount} from 'svelte'; | ||
import {url,formatPath} from './../dist/aors_lib'; | ||
export let base='/'; | ||
let fallback = false; | ||
setContext('ROUTER:base',formatPath(base)); | ||
setContext('ROUTER:fallback',cb => fallback ? console.error("Fallback already exist") : fallback=cb); | ||
</script> | ||
|
||
<slot></slot> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export {default as Router} from './Router.svelte'; | ||
export {default as Route} from './Route.svelte'; | ||
export * from './../dist/aors_lib'; |
Oops, something went wrong.