refactor: use ??= operator for cleaner globalThis singleton init

Addresses greptile review: collapses the if-guard + assignment into
a single ??= expression so TypeScript can narrow the type without
a non-null assertion.
This commit is contained in:
Eric Lytle
2026-03-02 23:31:44 +00:00
committed by Peter Steinberger
parent 0d8beeb4e5
commit d0a3743abd

View File

@@ -213,10 +213,10 @@ export type InternalHookHandler = (event: InternalHookEvent) => Promise<void> |
const _g = globalThis as typeof globalThis & {
__openclaw_internal_hook_handlers__?: Map<string, InternalHookHandler[]>;
};
if (!_g.__openclaw_internal_hook_handlers__) {
_g.__openclaw_internal_hook_handlers__ = new Map<string, InternalHookHandler[]>();
}
const handlers = _g.__openclaw_internal_hook_handlers__;
const handlers = (_g.__openclaw_internal_hook_handlers__ ??= new Map<
string,
InternalHookHandler[]
>());
const log = createSubsystemLogger("internal-hooks");
/**