fix(core): update

This commit is contained in:
2020-06-03 14:08:08 +00:00
parent 3564095f06
commit 9c4a81d9cd
4 changed files with 12 additions and 12 deletions

View File

@ -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
});
}

View File

@ -1,5 +1,3 @@
import * as pathToRegExp from 'path-to-regexp';
export {
pathToRegExp
};
export { pathToRegExp };