@foxpage/foxpage-manager
Version:
foxpage resource manager
62 lines (61 loc) • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RouterImpl = void 0;
const common_1 = require("../common");
/**
* foxpage router
* for internal route and dynamic route of customize
*
* @export
* @class RouterInstance
* @implements {Router}
*/
class RouterImpl {
constructor(app) {
this.routeMap = new Map();
this.logger = (0, common_1.createLogger)(`App@${app.appId} router Manager`);
}
/**
* register the route
*
* @param {Route} route
* @return {*}
*/
register(routes) {
routes.forEach(route => {
var _a;
if (!route.pathname) {
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error('register router failed: pathname is invalid.');
}
else {
this.routeMap.set(route.pathname, route);
}
});
}
/**
* unregister the route
*
* @param {Route} route
*/
unregister(route) {
if (route.pathname) {
this.routeMap.delete(route.pathname);
}
}
/**
* get the route by pathname
*
* @param {string} pathname
* @return {*}
*/
getRoute(pathname) {
return this.routeMap.get(pathname) || null;
}
/**
* destroy the cache
*/
destroy() {
this.routeMap.clear();
}
}
exports.RouterImpl = RouterImpl;