@storeon/router
Advanced tools
Comparing version 1.2.0 to 2.0.0
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 2.0.0 | ||
* Improve types. | ||
## 1.2.0 | ||
@@ -5,0 +8,0 @@ * Improve types. |
import { StoreonModule } from "storeon"; | ||
declare namespace createRouter{ | ||
export type RoutesState<MatchParams> = { | ||
[routerKey]: { | ||
match: MatchParams | boolean, | ||
path: string, | ||
params: string[], | ||
} | ||
} | ||
} | ||
/** | ||
* Router key on store | ||
*/ | ||
export const routerKey: unique symbol; | ||
/** | ||
* Event changes a path | ||
*/ | ||
export const routerChanged: unique symbol; | ||
/** | ||
* Navigate event | ||
*/ | ||
export const routerNavigate: unique symbol; | ||
export type RouterRecordState<MatchParameters> = { | ||
match: MatchParameters | false; | ||
path: string; | ||
params: string[]; | ||
}; | ||
export type RouterState<MatchParameters> = { | ||
[routerKey]: RouterRecordState<MatchParameters>; | ||
}; | ||
export type RouterEvents<MatchParameters> = { | ||
[routerChanged]: RouterState<MatchParameters>; | ||
[routerNavigate]: string; | ||
}; | ||
export type Path = string | RegExp; | ||
export type Callback<MatchParams> = (...props: string[]) => MatchParams; | ||
export type Route<MatchParam> = [Path, Callback<MatchParam>]; | ||
export type Callback<MatchParameters> = ( | ||
...properties: string[] | ||
) => MatchParameters; | ||
export type Route<MatchParameter> = [Path, Callback<MatchParameter>]; | ||
export function createRouter<MatchParam>(routes: Route<MatchParam>[]): StoreonModule<createRouter.RoutesState<MatchParam>>; | ||
export const routerKey: unique symbol; | ||
export const routerChanged: unique symbol; | ||
export const routerNavigate: unique symbol; | ||
export function createRouter<MatchParameter>( | ||
routes: Route<MatchParameter>[], | ||
): StoreonModule<RouterState<MatchParameter>, RouterEvents<MatchParameter>>; |
@@ -9,3 +9,3 @@ let loc = location | ||
/** | ||
* Changed event | ||
* Event changes a path | ||
*/ | ||
@@ -20,3 +20,3 @@ let routerChanged = Symbol() | ||
/** | ||
* Router routerKey on store | ||
* Router key on store | ||
*/ | ||
@@ -77,6 +77,3 @@ let routerKey = Symbol('route') | ||
event.preventDefault() | ||
store.dispatch( | ||
routerNavigate, | ||
link.href.slice(loc.origin.length) | ||
) | ||
store.dispatch(routerNavigate, link.href.slice(loc.origin.length)) | ||
} | ||
@@ -83,0 +80,0 @@ }) |
{ | ||
"name": "@storeon/router", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "Storeon module for URL routing", | ||
@@ -13,8 +13,10 @@ "main": "index.cjs", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"require": "./index.cjs", | ||
"import": "./index.js" | ||
} | ||
"import": "./index.js", | ||
"types": "./index.d.ts" | ||
}, | ||
"./package.json": "./package.json", | ||
"./index.d.ts": "./index.d.ts" | ||
} | ||
} |
@@ -6,5 +6,5 @@ # Storeon Router | ||
[Storeon] Router which solves the problem of routing your application, providing full control over the route. | ||
[Storeon] Router solves the problems of routing while seamlessly providing full control. | ||
It size is 577 bytes (minified and gzipped) and uses [Size Limit] to control size. | ||
Its size is 577 bytes (minified and gzipped) and uses [Size Limit] to control size. | ||
@@ -11,0 +11,0 @@ [Storeon]: https://github.com/storeon/storeon |
Sorry, the diff of this file is not supported yet
11028
259