Compare commits

..

No commits in common. "master" and "v1.2.0" have entirely different histories.

5 changed files with 3993 additions and 5019 deletions

View File

@ -1,28 +1,5 @@
# Changelog # Changelog
## 2024-10-06 - 1.3.2 - fix(core)
Fix TypeScript type definition for route match function
- Updated the type definition for the matchFunction in the SmartRouter class to include a generic parameter.
## 2024-10-06 - 1.3.1 - fix(dependencies)
Updated dependencies to latest versions, resolving compatibility issues and improving performance.
- Updated devDependencies to their latest versions, including tsbuild, tsbundle, tstest, tapbundle, and @types/node
- Updated dependencies to latest versions of lik, smartrx, and path-to-regexp
## 2024-10-06 - 1.3.0 - feat(smartrouter)
Add destroy method to SmartRouter class.
- Introduced a destroy method to the SmartRouter class for cleaning up event listeners and route references.
- Refactored popstate event listener to be removable, improving resource management and preventing memory leaks.
## 2024-10-06 - 1.2.1 - fix(core)
Ensure stability and performance improvements
- Improves platform compatibility for modern web applications.
- Enhances stability of the routing logic within SmartRouter class.
## 2024-10-06 - 1.2.0 - feat(core) ## 2024-10-06 - 1.2.0 - feat(core)
Add support for base paths and sub-routers. Add support for base paths and sub-routers.

View File

@ -1,6 +1,6 @@
{ {
"name": "@push.rocks/smartrouter", "name": "@push.rocks/smartrouter",
"version": "1.3.2", "version": "1.2.0",
"private": false, "private": false,
"description": "A JavaScript library providing routing capabilities for web applications.", "description": "A JavaScript library providing routing capabilities for web applications.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -14,16 +14,16 @@
"buildDocs": "tsdoc" "buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.1.84", "@git.zone/tsbuild": "^2.1.70",
"@git.zone/tsbundle": "^2.0.15", "@git.zone/tsbundle": "^2.0.7",
"@git.zone/tstest": "^1.0.90", "@git.zone/tstest": "^1.0.81",
"@push.rocks/tapbundle": "^5.3.0", "@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^22.7.4" "@types/node": "^20.6.0"
}, },
"dependencies": { "dependencies": {
"@push.rocks/lik": "^6.0.15", "@push.rocks/lik": "^6.0.5",
"@push.rocks/smartrx": "^3.0.7", "@push.rocks/smartrx": "^3.0.6",
"path-to-regexp": "^8.2.0" "path-to-regexp": "^6.2.0"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

8947
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartrouter', name: '@push.rocks/smartrouter',
version: '1.3.2', version: '1.2.0',
description: 'A JavaScript library providing routing capabilities for web applications.' description: 'A JavaScript library providing routing capabilities for web applications.'
} }

View File

@ -32,7 +32,7 @@ export class SmartRouter {
* the routes we are handling * the routes we are handling
*/ */
public routes: Array<{ public routes: Array<{
matchFunction: plugins.pathToRegExp.MatchFunction<any>; matchFunction: plugins.pathToRegExp.MatchFunction;
handler: THandlerFunction; handler: THandlerFunction;
}> = []; }> = [];
@ -41,11 +41,6 @@ export class SmartRouter {
*/ */
private basePath: string; private basePath: string;
/**
* Reference to the event listener function for cleanup
*/
private popstateListener: (event: PopStateEvent) => void;
/** /**
* Creates an instance of Router. * Creates an instance of Router.
*/ */
@ -58,11 +53,10 @@ export class SmartRouter {
this.basePath = basePath; this.basePath = basePath;
// lets subscribe to route changes // lets subscribe to route changes
this.popstateListener = (popStateEventArg) => { window.addEventListener('popstate', (popStateEventArg) => {
popStateEventArg.preventDefault(); popStateEventArg.preventDefault();
this._handleRouteState(); this._handleRouteState();
}; });
window.addEventListener('popstate', this.popstateListener);
} }
/** /**
@ -125,14 +119,4 @@ export class SmartRouter {
} as IRouteInfo); // not waiting here } as IRouteInfo); // not waiting here
} }
} }
/**
* Destroy the router instance, removing all external references
*/
public destroy() {
// Remove the event listener for popstate
window.removeEventListener('popstate', this.popstateListener);
// Clear all routes
this.routes = [];
}
} }