Primitives / foldkit-primitives/state

History

namespace · packages/primitives/src/state/history.ts:114

const History = {
  start,
  push,
  undo,
  redo,
  goTo,
  clear,
  close,
  revert,
  canUndo,
  canRedo,
}

The steps of a history as pure functions of its Model.

In the guides

Members

History.start

function · packages/primitives/src/state/history.ts:20

start<Value>(present: Value): HistoryModel<Value>

A history whose present is value, with nothing to undo.

History.push

function · packages/primitives/src/state/history.ts:35

push<Value>(
  model: HistoryModel<Value>,
  value: Value,
  options: {
    readonly capacity: number
    readonly group?: string | null | undefined
  },
): HistoryModel<Value>

Records value as the present; the same group as the last push joins its step.

History.undo

function · packages/primitives/src/state/history.ts:53

undo<Value>(model: HistoryModel<Value>): HistoryModel<Value>

One step back, or the Model as it was when there is none.

History.redo

function · packages/primitives/src/state/history.ts:64

redo<Value>(model: HistoryModel<Value>): HistoryModel<Value>

One step forward, or the Model as it was when there is none.

History.goTo

function · packages/primitives/src/state/history.ts:75

goTo<Value>(model: HistoryModel<Value>, step: number): HistoryModel<Value>

The value at step made the present, counting every kept value from the oldest (0), so the present is at past.length: what a click on a step's thumbnail does. The Model as it was for the present or a step not kept.

History.clear

function · packages/primitives/src/state/history.ts:87

clear<Value>(model: HistoryModel<Value>): HistoryModel<Value>

Nothing to undo or redo, the present kept.

History.close

function · packages/primitives/src/state/history.ts:92

close<Value>(model: HistoryModel<Value>): HistoryModel<Value>

The next push starts a step of its own, whatever its group: a group ends here.

History.revert

function · packages/primitives/src/state/history.ts:95

revert<Value>(model: HistoryModel<Value>, group: string): HistoryModel<Value>

The step group is making taken back, and not redoable: what a cancelled edit, or one that ended where it began, leaves. The Model as it was when the last push was not of group. What the group's first push dropped stays dropped: the redo future it cleared, and an entry capacity evicted; with a capacity of 0 nothing was kept, so the present stays and only the group ends.

History.canUndo

function · packages/primitives/src/state/history.ts:108

canUndo<Value>(model: HistoryModel<Value>): boolean

Whether Undo would move: the past is non-empty.

History.canRedo

function · packages/primitives/src/state/history.ts:111

canRedo<Value>(model: HistoryModel<Value>): boolean

Whether Redo would move: the future is non-empty.