Skip to content

@graphty/graphty-element / session / SessionHistory

Interface: SessionHistory ​

Defined in: graphty-element/src/session/types.ts:1514

The session's undo history. steps, pending and nextUndo are frozen values, the identical objects between changes; version moves on every history:changed, so a React host can subscribe with useSyncExternalStore(subscribe, () => session.history.version).

Properties ​

bytes ​

readonly bytes: number

Defined in: graphty-element/src/session/types.ts:1529

What every step retains, in bytes.


limitBytes ​

limitBytes: number

Defined in: graphty-element/src/session/types.ts:1536

The byte budget. Default 256 MiB. When a record goes past it, or past limitSteps, the oldest steps (then the farthest redo steps) are dropped until the history is within 90% of both budgets, so the work of dropping is spread over many records. Lowering a budget below what the history holds trims it the same way at once.


limitSteps ​

limitSteps: number

Defined in: graphty-element/src/session/types.ts:1541

The step budget. Default 1000. Going past it trims the history to 90% of it, rounded down, as limitBytes describes: with a budget of 10, the eleventh step leaves 9.


nextUndo ​

readonly nextUndo: { kind: "cancel"; pending: readonly PendingStep[]; } | { kind: "undo"; step: HistoryStep; } | null

Defined in: graphty-element/src/session/types.ts:1524

What the next undo() will do: cancel pending work, undo a step, or nothing (null).


pending ​

readonly pending: readonly PendingStep[]

Defined in: graphty-element/src/session/types.ts:1522

Undoable work dispatched and not yet recorded, oldest first.


position ​

readonly position: number

Defined in: graphty-element/src/session/types.ts:1520

How many steps are applied.


steps ​

readonly steps: readonly HistoryStep[]

Defined in: graphty-element/src/session/types.ts:1518

Oldest first; steps[position..] have been undone and can be redone.


version ​

readonly version: number

Defined in: graphty-element/src/session/types.ts:1516

Bumped on every history:changed.

Methods ​

cancel() ​

cancel(pending): readonly PendingStep[]

Defined in: graphty-element/src/session/types.ts:1554

Cancel a pending item, and every later-dispatched item that depends on what it writes.

Parameters ​

pending ​

PendingId

The item.

Returns ​

readonly PendingStep[]

Every item cancelled; empty when the id is not pending.


clear() ​

clear(): void

Defined in: graphty-element/src/session/types.ts:1556

Drop every step, cancelling pending work: the current state becomes the baseline.

Returns ​

void


restoreTo() ​

restoreTo(step): Promise<HistoryOutcome>

Defined in: graphty-element/src/session/types.ts:1548

Move to the state just after a step, or to the baseline with null, as the equivalent run of undos or redos. Resolves once the picture matches the state.

Parameters ​

step ​

HistoryStepId | null

The step, or null for the state before every step.

Returns ​

Promise<HistoryOutcome>

What was done.