fix(core): update
This commit is contained in:
parent
3564095f06
commit
9c4a81d9cd
@ -19,7 +19,7 @@ TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x
|
||||
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartrouter)](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartrouter)](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartrouter)](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartrouter)](https://lossless.cloud)
|
||||
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
|
||||
|
||||
|
16
ts/index.ts
16
ts/index.ts
@ -1,6 +1,6 @@
|
||||
import * as plugins from './smartrouter.plugins';
|
||||
|
||||
const routeLog = (message) => {
|
||||
const routeLog = message => {
|
||||
console.log(`%c[Router]%c ${message}`, 'color: rgb(255, 105, 100);', 'color: inherit');
|
||||
};
|
||||
|
||||
@ -13,13 +13,16 @@ export interface IRouterOptions {
|
||||
*/
|
||||
export class SmartRouter {
|
||||
public options: IRouterOptions = {
|
||||
debug: false,
|
||||
debug: false
|
||||
};
|
||||
|
||||
/**
|
||||
* the routes we are handling
|
||||
*/
|
||||
public routes: Array<{ matchFunction: plugins.pathToRegExp.MatchFunction; handler: <T extends object>(matchArg: plugins.pathToRegExp.Match<T>) => Promise<any> }> = [];
|
||||
public routes: Array<{
|
||||
matchFunction: plugins.pathToRegExp.MatchFunction;
|
||||
handler: <T extends object>(matchArg: plugins.pathToRegExp.Match<T>) => Promise<any>;
|
||||
}> = [];
|
||||
|
||||
/**
|
||||
* Creates an instance of Router.
|
||||
@ -28,11 +31,11 @@ export class SmartRouter {
|
||||
// lets set the router options
|
||||
this.options = {
|
||||
...this.options,
|
||||
...optionsArg,
|
||||
...optionsArg
|
||||
};
|
||||
|
||||
// lets subscribe to route changes
|
||||
window.addEventListener('popstate', (popStateEventArg) => {
|
||||
window.addEventListener('popstate', popStateEventArg => {
|
||||
popStateEventArg.preventDefault();
|
||||
this._handleRouteState();
|
||||
});
|
||||
@ -59,10 +62,9 @@ export class SmartRouter {
|
||||
* @param {function} handlerArg
|
||||
*/
|
||||
public on(routeArg: string, handlerArg: () => Promise<any>) {
|
||||
|
||||
this.routes.push({
|
||||
matchFunction: plugins.pathToRegExp.match(routeArg),
|
||||
handler: handlerArg,
|
||||
handler: handlerArg
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
import * as pathToRegExp from 'path-to-regexp';
|
||||
|
||||
export {
|
||||
pathToRegExp
|
||||
};
|
||||
export { pathToRegExp };
|
||||
|
Loading…
Reference in New Issue
Block a user