# DevtoolsStore

Source: /tuil/docs/reference/packages/devtools/api/devtools-store
Locale: en

class exported by @mwillbanks/tuil-devtools.



{/* Generated by tooling/docs/generate-reference.ts. */}

## class [#class]

Public class exported by `@mwillbanks/tuil-devtools`.

```ts
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 [#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`](/tuil/docs/reference/packages/events/api/event-map), [`TuilExtensionPoints`](/tuil/docs/reference/packages/tuil/api/tuil-extension-points), [`TuilRuntime`](/tuil/docs/reference/packages/tuil/api/tuil-runtime) |
| `#events`           | `ObservedEvent[]`                                                                                         | Yes      | The `#events` member uses the `ObservedEvent[]` contract.                                                                                          | [`ObservedEvent`](/tuil/docs/reference/packages/events/api/observed-event)                                                                                                                                          |
| `#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`](/tuil/docs/reference/packages/devtools/api/devtools-panel), [`RuntimeInspection`](/tuil/docs/reference/packages/devtools/api/runtime-inspection)                                                       |
| `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 [#parameters]

This declaration has no public members.

## Returns [#returns]

This declaration does not return a value.

## Throws [#throws]

No thrown errors are documented for this declaration.

## Related types [#related-types]

* [`DevtoolsPanel`](/tuil/docs/reference/packages/devtools/api/devtools-panel)
* [`RuntimeInspection`](/tuil/docs/reference/packages/devtools/api/runtime-inspection)

## Source [#source]

[View the secondary source reference](https://github.com/mwillbanks/tuil/blob/main/packages/devtools/src/index.tsx)

## Package [#package]

[@mwillbanks/tuil-devtools](/tuil/docs/reference/packages/devtools)
