Skip to content

debug-switches

A registry of debug switches: named, app-wide booleans that change behavior while debugging.

A debug namespace (see debug.ts) controls logging only. Behavior that should differ while debugging, such as not terminating an operation paused on a breakpoint, is a debug switch instead, so turning logging on never changes what the code does.

The definitions, the values and the change listeners all live in the shared state bag (typescript-lib-state.ts) as plain data, so every copy of this library loaded in one realm, such as the copy each Obsidian plugin bundles, sees one value per switch. A tool such as a debug-settings UI lists every registered switch with getDebugSwitches and needs no change when a library or plugin adds one.

Interface Description
DebugSwitch A handle to a registered debug switch.
DebugSwitchChange A change of a debug switch’s value, passed to an onDebugSwitchChanged listener.
DebugSwitchDefinition The definition of a debug switch.
Function Description
getDebugSwitch Gets a registered debug switch.
getDebugSwitches Gets every registered debug switch, sorted by id.
getTerminateOnTimeoutDebugSwitch Gets the debug switch that decides whether a runWithTimeout call without its own onTimeout terminates the operation when it times out. Its id is typescript-lib:terminate-on-timeout and it is on by default. Switch it off while debugging, so an operation paused on a breakpoint is not terminated under the debugger. The timeout is still logged through the Async:runWithTimeout debugger.
onDebugSwitchChanged Adds a listener called whenever a debug switch’s value changes, in any loaded copy of this library.
registerDebugSwitch Registers a debug switch. Registering an id again is idempotent: the first definition is kept, and the returned handle reads the same value. A value set with setDebugSwitch before the switch was registered is kept, not reset to the default.
setDebugSwitch Sets the value of a debug switch, notifying the onDebugSwitchChanged listeners if it changed. The switch does not have to be registered yet: the value is kept, and the switch takes it when it registers. That lets a settings store re-apply saved values before every library or plugin that owns a switch has loaded.
Type Description
DebugSwitchChangeListener The listener of onDebugSwitchChanged.