Skip to content

Latest commit

 

History

History
99 lines (61 loc) · 1.67 KB

Halogen-Mixin-UndoRedo.md

File metadata and controls

99 lines (61 loc) · 1.67 KB

Module Documentation

Module Halogen.Mixin.UndoRedo

This module provides a generic undo/redo capability.

UndoRedoInput

data UndoRedoInput
  = Undo 
  | Redo 

Adds two new input types:

  • Undo - move to the previous state
  • Redo - move to the next state

SupportsUndoRedo

class SupportsUndoRedo input where
  fromUndoRedo :: UndoRedoInput -> input
  toUndoRedo :: input -> Maybe UndoRedoInput

This type class identifies those input types which support the Undo and Redo actions

undo

undo :: forall i. (SupportsUndoRedo i) => i

The undo action

redo

redo :: forall i. (SupportsUndoRedo i) => i

The redo action

UndoRedoState

data UndoRedoState s

Modifies the state type to include its past and future.

canUndo

canUndo :: forall s. UndoRedoState s -> Boolean

true if the state supports the undo operation.

canRedo

canRedo :: forall s. UndoRedoState s -> Boolean

true if the state supports the redo operation.

getState

getState :: forall s. UndoRedoState s -> s

Get the state at the current time

undoRedoState

undoRedoState :: forall s. s -> UndoRedoState s

Create a state with no past and no future

withUndoRedo

withUndoRedo :: forall s i. (SupportsUndoRedo i) => (s -> i -> s) -> UndoRedoState s -> i -> UndoRedoState s

Lift a step function to support the undo and redo operations.

The view should use the canUndo and canRedo functions to determine whether or not to enable the corresponding controls.