DevtoolsStore
class exported by @mwillbanks/tuil-devtools.
class
Public class exported by @mwillbanks/tuil-devtools.
export class DevtoolsStore {
readonly #runtime: TuilRuntime;
readonly #events: ObservedEvent[] = [];
readonly #observers = new Set<() => void>();
readonly #maxEvents: number;
readonly #disposeObservers: readonly (() => void)[];
#version = 0;
#disposed = false;
constructor(
runtime: TuilRuntime,
options: { readonly maxEvents?: number } = {},
) {
this.#runtime = runtime;
this.#maxEvents = options.maxEvents ?? 200;
if (!Number.isSafeInteger(this.#maxEvents) || this.#maxEvents < 1) {
throw new Error("Devtools maxEvents must be a positive integer");
}
this.#events.push(...runtime.events.history().slice(-this.#maxEvents));
const commandObserver = runtime.commands.observeRegistry(() =>
this.#notify(),
);
this.#disposeObservers = [
runtime.events.observe((event) => {
this.#events.push(event);
if (this.#events.length > this.#maxEvents) this.#events.shift();
this.#notify();
}),
() => {
void commandObserver.dispose();
},
runtime.focus.observe(() => this.#notify()),
runtime.hotkeys.observe(() => this.#notify()),
runtime.editorSessions.observe(() => this.#notify()),
runtime.logPipelines.observe(() => this.#notify()),
runtime.streamingPipelines.observe(() => this.#notify()),
runtime.extensions.devtoolsPanels.observe(() => this.#notify()),
];
}
subscribe = (observer: () => void): (() => void) => {
this.#observers.add(observer);
return () => this.#observers.delete(observer);
};
version = (): number => this.#version;
inspect(panel: DevtoolsPanel): RuntimeInspection {
return inspectRuntime(this.#runtime, panel, this.#events);
}
refresh(): void {
this.#notify();
}
dispose(): void {
if (this.#disposed) return;
this.#disposed = true;
for (const dispose of this.#disposeObservers) dispose();
this.#observers.clear();
}
#notify(): void {
if (this.#disposed) return;
this.#version += 1;
for (const observer of this.#observers) observer();
}
}Members
| Member | Type | Required | Description | Related types |
|---|---|---|---|---|
#runtime | TuilRuntime<import("@mwillbanks/tuil-events").EventMap, import("@mwillbanks/tuil").TuilExtensionPoints> | Yes | The #runtime member uses the TuilRuntime<import("@mwillbanks/tuil-events").EventMap, import("@mwillbanks/tuil").TuilExtensionPoints> contract. | EventMap, TuilExtensionPoints, TuilRuntime |
#events | ObservedEvent[] | Yes | The #events member uses the ObservedEvent[] contract. | ObservedEvent |
#observers | Set<() => void> | Yes | The #observers member uses the Set<() => void> contract. | — |
#maxEvents | number | Yes | The #maxEvents member uses the number contract. | — |
#disposeObservers | readonly (() => void)[] | Yes | The #disposeObservers member uses the readonly (() => void)[] contract. | — |
#version | number | Yes | The #version member uses the number contract. | — |
#disposed | boolean | Yes | The #disposed member uses the boolean contract. | — |
__constructor | any | Yes | The __constructor member uses the any contract. | — |
subscribe | (observer: () => void) => (() => void) | Yes | The subscribe member uses the (observer: () => void) => (() => void) contract. | — |
version | () => number | Yes | The version member uses the () => number contract. | — |
inspect | (panel: DevtoolsPanel) => RuntimeInspection | Yes | The inspect member uses the (panel: DevtoolsPanel) => RuntimeInspection contract. | DevtoolsPanel, RuntimeInspection |
refresh | () => void | Yes | The refresh member uses the () => void contract. | — |
dispose | () => void | Yes | The dispose member uses the () => void contract. | — |
#notify | () => void | Yes | The #notify member uses the () => void contract. | — |
Parameters
This declaration has no public members.
Returns
This declaration does not return a value.
Throws
No thrown errors are documented for this declaration.
Related types
Source
View the secondary source reference