mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
refactor(assets): use ES6 # private fields instead of TS private
Convert all TypeScript `private` and `private readonly` declarations to ES6 `#` syntax for true runtime privacy. TypeScript's `private` keyword only provides compile-time checking but fields remain accessible in compiled JavaScript.
This commit is contained in:
@@ -22,14 +22,14 @@ export type Handler<T> = T extends void
|
||||
|
||||
/** Typed event bus — wraps DOM CustomEvents with type-safe emit/on/off. */
|
||||
export class TypedEventBus {
|
||||
private target = document
|
||||
#target = document
|
||||
|
||||
on<K extends keyof FixItEventMap>(event: K, handler: Handler<FixItEventMap[K]>): void {
|
||||
this.target.addEventListener(event as string, handler as EventListener)
|
||||
this.#target.addEventListener(event as string, handler as EventListener)
|
||||
}
|
||||
|
||||
off<K extends keyof FixItEventMap>(event: K, handler: Handler<FixItEventMap[K]>): void {
|
||||
this.target.removeEventListener(event as string, handler as EventListener)
|
||||
this.#target.removeEventListener(event as string, handler as EventListener)
|
||||
}
|
||||
|
||||
emit<K extends keyof FixItEventMap>(
|
||||
@@ -37,7 +37,7 @@ export class TypedEventBus {
|
||||
...args: FixItEventMap[K] extends void ? [] : [FixItEventMap[K]]
|
||||
): void {
|
||||
const detail = args[0]
|
||||
this.target.dispatchEvent(
|
||||
this.#target.dispatchEvent(
|
||||
detail !== undefined
|
||||
? new CustomEvent(event as string, { detail })
|
||||
: new CustomEvent(event as string),
|
||||
|
||||
Reference in New Issue
Block a user