fix(core): update
This commit is contained in:
parent
3564095f06
commit
9c4a81d9cd
@ -36,4 +36,4 @@
|
|||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -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/)
|
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)
|
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 (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)
|
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)
|
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';
|
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');
|
console.log(`%c[Router]%c ${message}`, 'color: rgb(255, 105, 100);', 'color: inherit');
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -13,13 +13,16 @@ export interface IRouterOptions {
|
|||||||
*/
|
*/
|
||||||
export class SmartRouter {
|
export class SmartRouter {
|
||||||
public options: IRouterOptions = {
|
public options: IRouterOptions = {
|
||||||
debug: false,
|
debug: false
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the routes we are handling
|
* 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.
|
* Creates an instance of Router.
|
||||||
@ -28,11 +31,11 @@ export class SmartRouter {
|
|||||||
// lets set the router options
|
// lets set the router options
|
||||||
this.options = {
|
this.options = {
|
||||||
...this.options,
|
...this.options,
|
||||||
...optionsArg,
|
...optionsArg
|
||||||
};
|
};
|
||||||
|
|
||||||
// lets subscribe to route changes
|
// lets subscribe to route changes
|
||||||
window.addEventListener('popstate', (popStateEventArg) => {
|
window.addEventListener('popstate', popStateEventArg => {
|
||||||
popStateEventArg.preventDefault();
|
popStateEventArg.preventDefault();
|
||||||
this._handleRouteState();
|
this._handleRouteState();
|
||||||
});
|
});
|
||||||
@ -59,10 +62,9 @@ export class SmartRouter {
|
|||||||
* @param {function} handlerArg
|
* @param {function} handlerArg
|
||||||
*/
|
*/
|
||||||
public on(routeArg: string, handlerArg: () => Promise<any>) {
|
public on(routeArg: string, handlerArg: () => Promise<any>) {
|
||||||
|
|
||||||
this.routes.push({
|
this.routes.push({
|
||||||
matchFunction: plugins.pathToRegExp.match(routeArg),
|
matchFunction: plugins.pathToRegExp.match(routeArg),
|
||||||
handler: handlerArg,
|
handler: handlerArg
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import * as pathToRegExp from 'path-to-regexp';
|
import * as pathToRegExp from 'path-to-regexp';
|
||||||
|
|
||||||
export {
|
export { pathToRegExp };
|
||||||
pathToRegExp
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user