htmx-router 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -258,7 +258,7 @@ export class SharedEventSource {
258
258
  // Without this graceful shutdowns will hang indefinitely
259
259
  const keepAlive = new EventSourceSet();
260
260
  const interval = setInterval(() => { keepAlive.pulse(); }, 10_000);
261
- // Lifecycle.addEventListener('shutdown', () => {
262
- // clearInterval(interval);
263
- // keepAlive.closeAll();
264
- // });
261
+ Lifecycle.addEventListener('shutdown', () => {
262
+ clearInterval(interval);
263
+ keepAlive.closeAll();
264
+ });
package/dist/event.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { Singleton } from './util/singleton';
1
2
  export class ShutdownEvent extends CustomEvent {
2
3
  constructor(signal) {
3
4
  super('shutdown', { detail: { signal } });
@@ -29,7 +30,7 @@ class LifecycleController extends EventTarget {
29
30
  globalThis.window.addEventListener('beforeunload', () => trigger('BEFOREUNLOAD'));
30
31
  }
31
32
  if (process) {
32
- process.on('SIGINT', () => trigger('SIGINT'));
33
+ // process.on('SIGINT', () => trigger('SIGINT'));
33
34
  process.on('SIGTERM', () => trigger('SIGTERM'));
34
35
  process.on('SIGHUP', () => trigger('SIGHUP'));
35
36
  }
@@ -38,7 +39,7 @@ class LifecycleController extends EventTarget {
38
39
  Deno.addSignalListener('SIGTERM', () => trigger('SIGTERM'));
39
40
  }
40
41
  Deno.addSignalListener("SIGHUP", () => trigger('SIGHUP'));
41
- Deno.addSignalListener("SIGINT", () => trigger('SIGTERM'));
42
+ // Deno.addSignalListener("SIGINT", () => trigger('SIGINT'));
42
43
  }
43
44
  }
44
45
  #trigger(signal) {
@@ -49,4 +50,4 @@ class LifecycleController extends EventTarget {
49
50
  this.dispatchEvent(new ShutdownEvent(signal));
50
51
  }
51
52
  }
52
- export const Lifecycle = new LifecycleController();
53
+ export const Lifecycle = Singleton('htmx-router-lifecycle', () => new LifecycleController());
@@ -0,0 +1 @@
1
+ export declare function Singleton<T>(name: string, cb: () => T): T;
@@ -0,0 +1,8 @@
1
+ // Borrowed & modified from https://github.com/jenseng/abuse-the-platform/blob/main/app/utils/singleton.ts
2
+ export function Singleton(name, cb) {
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ const g = globalThis;
5
+ g.__singletons ??= {};
6
+ g.__singletons[name] ??= cb();
7
+ return g.__singletons[name];
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "htmx-router",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "A lightweight SSR framework with server+client islands",
5
5
  "keywords": [ "htmx", "router", "client islands", "ssr", "vite" ],
6
6
  "type": "module",