diff options
Diffstat (limited to 'src/router.ts')
-rw-r--r-- | src/router.ts | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/router.ts b/src/router.ts index ff6c724..2d229b0 100644 --- a/src/router.ts +++ b/src/router.ts @@ -1,14 +1,8 @@ import * as Config from 'config' -export enum Kind { - Form, - Timer, -} - -export interface Route { - kind: Kind, - config: Config.Config -} +export type Route + = { name: 'form', config: Config.Config } + | { name: 'timer', config: Config.Config } export function from(location: Location): Route { const hash = location.hash.slice(1) @@ -16,7 +10,7 @@ export function from(location: Location): Route { const path = parts[0] const search = parts.length > 1 ? parts[1] : '' - const kind = path.startsWith('/timer') ? Kind.Timer : Kind.Form + const name = path.startsWith('/timer') ? 'timer' : 'form' let config = Config.init() if (search.length > 0) { search.split('&').forEach(entry => { @@ -35,11 +29,11 @@ export function from(location: Location): Route { const params = search.split('&') } - return { kind, config } + return { name, config } } export function toString(route: Route): string { - const path = route.kind === Kind.Form ? '/' : '/timer' + const path = route.name === 'form' ? '/' : '/timer' let query = '' if (route.config !== undefined) { const { warmup, tabatas, prepare, cycles, work, rest } = route.config |