Skip to content

Commit d0a3743

Browse files
Drickonsteipete
authored andcommitted
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.
1 parent 0d8beeb commit d0a3743

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/hooks/internal-hooks.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ export type InternalHookHandler = (event: InternalHookEvent) => Promise<void> |
213213
const _g = globalThis as typeof globalThis & {
214214
__openclaw_internal_hook_handlers__?: Map<string, InternalHookHandler[]>;
215215
};
216-
if (!_g.__openclaw_internal_hook_handlers__) {
217-
_g.__openclaw_internal_hook_handlers__ = new Map<string, InternalHookHandler[]>();
218-
}
219-
const handlers = _g.__openclaw_internal_hook_handlers__;
216+
const handlers = (_g.__openclaw_internal_hook_handlers__ ??= new Map<
217+
string,
218+
InternalHookHandler[]
219+
>());
220220
const log = createSubsystemLogger("internal-hooks");
221221

222222
/**

0 commit comments

Comments
 (0)