Primitives / foldkit-primitives/state

History

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

const History = {
  start,
  push,
  undo,
  redo,
  goTo,
  clear,
  close,
  revert,
  map,
  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:23

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:56

push<Value>(
  model: HistoryModel<Value>,
  value: Value,
  options: PushOptions<Value>,
): 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:81

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:93

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:105

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:118

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

Nothing to undo or redo, the present kept.

History.close

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

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:126

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.map

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

map<Value>(
  model: HistoryModel<Value>,
  change: (value: Value) => Value,
): HistoryModel<Value>

Every kept value rewritten, with the steps and the group as they were: a change that belongs to no step of its own, such as a status that is updated everywhere it appears. The Model as it was when no value changes.

History.canUndo

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

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

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

History.canRedo

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

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

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