obsidian-dev-utils-state
LEGACY: provides access to the process-wide shared-state bag on the __obsidianDevUtils global. The name is the retired obsidian-dev-utils package’s; it stays because plugins bundling an older copy read and write the same bag, so it is a wire format rather than a name to copy. New generic state belongs in @mnaoumov/typescript-lib/typescript-lib-state (the Symbol.for('@mnaoumov/typescript-lib/state') slot).
The bag is stored on globalThis.__obsidianDevUtils, i.e. on the global object of the realm in which this library is loaded. Because a function’s globalThis resolves to its defining realm (not the caller’s), every consumer that bundles the library in the main Obsidian renderer shares the same bag, regardless of which window is currently active. This intentionally replaces the previous App-scoped storage, so callers no longer need to pass an App instance.
The generic, non-Obsidian state (the debuggers, the debug instance and the shared abort controller) lives in typescript-lib-state.ts instead. shareTypescriptLibStateWithObsidianDevUtilsState links the two, so plugins bundling an older copy of this library, which still keep that state here, share it with newer ones.
Functions
Section titled “Functions”| Function | Description |
|---|---|
| getObsidianDevUtilsState | Retrieves or creates a shared-state ValueWrapper for a given key on globalThis.__obsidianDevUtils. |
| resetObsidianDevUtilsState | Clears the shared-state bag on globalThis.__obsidianDevUtils. Intended for test isolation: call it before each test so accumulated state (debuggers, queues, registered handlers, etc.) does not leak between tests. |
| shareTypescriptLibStateWithObsidianDevUtilsState | Makes the generic shared state and __obsidianDevUtils hold the same ValueWrapper for each key that moved between them. A wrapper already under __obsidianDevUtils wins, because an older copy of this library loaded first and its callers already hold that instance. Otherwise the generic wrapper is published under __obsidianDevUtils, for older copies loaded later and for the devtools console. |