simple-boot-core
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -14,2 +14,5 @@ export declare class Intent<T = any, E = any> { | ||
}; | ||
getPathnameData(urlExpression: string): { | ||
[name: string]: string; | ||
} | undefined; | ||
} |
@@ -64,4 +64,24 @@ "use strict"; | ||
}); | ||
Intent.prototype.getPathnameData = function (urlExpression) { | ||
var urls = this.pathname.split('/'); | ||
var urlExpressions = urlExpression.split('/'); | ||
if (urls.length != urlExpressions.length) { | ||
return; | ||
} | ||
var data = {}; | ||
for (var i = 0; i < urlExpressions.length; i++) { | ||
var it_1 = urlExpressions[i]; | ||
var urlit = urls[i]; | ||
if (!it_1.startsWith(':')) { | ||
if (it_1 !== urlit) { | ||
return; | ||
} | ||
continue; | ||
} | ||
data[it_1.slice(1)] = urlit; | ||
} | ||
return data; | ||
}; | ||
return Intent; | ||
}()); | ||
exports.Intent = Intent; |
{ | ||
"name": "simple-boot-core", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"main": "SimpleApplication.js", | ||
@@ -47,4 +47,5 @@ "license": "MIT", | ||
"scripts": { | ||
"build": "rm -rf dist && tsc --outDir dist --declarationDir dist", | ||
"npm-build": "rm -rf dist && tsc --outDir dist --declarationDir dist && cp package.json dist && cp README.MD dist", | ||
"start:dev": "npm run start --workspace=dev", | ||
"build": "rm -rf dist && tsc --sourceMap false --outDir dist --declarationDir dist", | ||
"npm-build": "rm -rf dist && tsc --sourceMap false --outDir dist --declarationDir dist && cp package.json dist && cp README.MD dist", | ||
"npm-publish": "npm run npm-build && npm publish ./dist", | ||
@@ -54,4 +55,9 @@ "tsc": "tsc", | ||
}, | ||
"workspaces": [ | ||
"./", | ||
"example/" | ||
], | ||
"devDependencies": { | ||
"@types/jest": "^26.0.22", | ||
"@types/node": "^16.3.1", | ||
"@typescript-eslint/eslint-plugin": "^4.16.1", | ||
@@ -58,0 +64,0 @@ "@typescript-eslint/parser": "^4.16.1", |
@@ -7,7 +7,7 @@ import { Module } from "../module/Module"; | ||
export declare class Router implements IntentEvent { | ||
path: string; | ||
childs: ConstructorType<Router>[]; | ||
_path: string; | ||
_childs: ConstructorType<Router>[]; | ||
[name: string]: ConstructorType<Module> | any; | ||
private _simstanceManager; | ||
constructor(path?: string, childs?: ConstructorType<Router>[]); | ||
constructor(_path?: string, _childs?: ConstructorType<Router>[]); | ||
publish(intent: Intent): void; | ||
@@ -17,5 +17,5 @@ subscribe(intent: Intent): void; | ||
isRootUrl(parentRoots: string[], url: string): boolean; | ||
routing(parentRoots: string[], path: string): RouterModule | undefined; | ||
routing(parentRoots: string[], intent: Intent): RouterModule | undefined; | ||
canActivate(url: Intent, module: RouterModule): Promise<ConstructorType<Module> | undefined>; | ||
notFound(url: Intent): ConstructorType<Module> | undefined; | ||
} |
@@ -43,8 +43,8 @@ "use strict"; | ||
var Router = (function () { | ||
function Router(path, childs) { | ||
if (path === void 0) { path = ''; } | ||
if (childs === void 0) { childs = []; } | ||
function Router(_path, _childs) { | ||
if (_path === void 0) { _path = ''; } | ||
if (_childs === void 0) { _childs = []; } | ||
var _a; | ||
this.path = path; | ||
this.childs = childs; | ||
this._path = _path; | ||
this._childs = _childs; | ||
this._simstanceManager = (_a = SimGlobal_1.SimGlobal().application) === null || _a === void 0 ? void 0 : _a.simstanceManager; | ||
@@ -60,7 +60,7 @@ } | ||
var path = intent.pathname; | ||
var routerStrings = parentRouters.slice(1).map(function (it) { return it.path || ''; }); | ||
var routerStrings = parentRouters.slice(1).map(function (it) { return it._path || ''; }); | ||
var isRoot = this.isRootUrl(routerStrings, path); | ||
if (isRoot) { | ||
parentRouters.push(this); | ||
var module_1 = this.routing(routerStrings, path); | ||
var module_1 = this.routing(routerStrings, intent); | ||
if (module_1 === null || module_1 === void 0 ? void 0 : module_1.module) { | ||
@@ -70,3 +70,3 @@ return module_1; | ||
else { | ||
for (var _i = 0, _a = this.childs; _i < _a.length; _i++) { | ||
for (var _i = 0, _a = this._childs; _i < _a.length; _i++) { | ||
var child = _a[_i]; | ||
@@ -83,11 +83,15 @@ var route = this._simstanceManager.getOrNewSim(child); | ||
Router.prototype.isRootUrl = function (parentRoots, url) { | ||
return url.startsWith(parentRoots.join('') + (this.path || '')); | ||
return url.startsWith(parentRoots.join('') + (this._path || '')); | ||
}; | ||
Router.prototype.routing = function (parentRoots, path) { | ||
var urlRoot = parentRoots.join('') + this.path; | ||
Router.prototype.routing = function (parentRoots, intent) { | ||
var urlRoot = parentRoots.join('') + this._path; | ||
var regex = new RegExp('^' + urlRoot, 'i'); | ||
path = path.replace(regex, ''); | ||
var fieldModule = this[path]; | ||
if (fieldModule) { | ||
return new RouterModule_1.RouterModule(this, fieldModule); | ||
for (var _i = 0, _a = Object.keys(this).filter(function (it) { return !it.startsWith('_'); }); _i < _a.length; _i++) { | ||
var it_1 = _a[_i]; | ||
var pathnameData = intent.getPathnameData(it_1); | ||
if (pathnameData) { | ||
var rm = new RouterModule_1.RouterModule(this, this[it_1]); | ||
rm.pathData = pathnameData; | ||
return rm; | ||
} | ||
} | ||
@@ -94,0 +98,0 @@ }; |
@@ -8,4 +8,7 @@ import { Router } from './Router'; | ||
routerChains: R[]; | ||
pathData?: { | ||
[name: string]: string; | ||
}; | ||
constructor(router?: R | undefined, module?: ConstructorType<M> | undefined, routerChains?: R[]); | ||
getModuleInstance<T = M>(): T; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82154
1865
13