4 Commits

Author SHA1 Message Date
ab5298c5a0 1.3.0 2024-10-06 22:27:54 +02:00
c74c4e78a6 feat(smartrouter): Add destroy method to SmartRouter class. 2024-10-06 22:27:53 +02:00
fa8ec78c1c 1.2.1 2024-10-06 20:18:17 +02:00
bd943726eb fix(core): Ensure stability and performance improvements 2024-10-06 20:18:16 +02:00
4 changed files with 32 additions and 4 deletions

View File

@ -1,5 +1,17 @@
# Changelog # Changelog
## 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.2.0", "version": "1.3.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",

View File

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

View File

@ -41,6 +41,11 @@ 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.
*/ */
@ -53,10 +58,11 @@ export class SmartRouter {
this.basePath = basePath; this.basePath = basePath;
// lets subscribe to route changes // lets subscribe to route changes
window.addEventListener('popstate', (popStateEventArg) => { this.popstateListener = (popStateEventArg) => {
popStateEventArg.preventDefault(); popStateEventArg.preventDefault();
this._handleRouteState(); this._handleRouteState();
}); };
window.addEventListener('popstate', this.popstateListener);
} }
/** /**
@ -119,4 +125,14 @@ 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 = [];
}
} }