Skip to content

unyt-org/example-history-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DATEX History API Example

This is a example project demonstrating how to use the History API of DATEX. The API provides a way to undo and redo state changes of one or multiple pointers.

Usage

The history for a pointer can be managed by creating a new History object and adding the pointer to the history:

import { History } from "datex-core-legacy/utils/history.ts";

const entries = $$([]);
const history = new History();
history.add(entries);

Now, every state change of the entries array is recorded and can be undone or repeated:

entries.push("Entry 1");
entries.push("Entry 2");
entries.push("Entry 3");
console.log(entries) // ["Entry 1", "Entry 2", "Entry 3"]

// undo last change
history.back();
console.log(entries) // ["Entry 1", "Entry 2"]

// undo second last change
history.back();
console.log(entries) // ["Entry 1"]

// repeat second last change
history.forward();
console.log(entries) // ["Entry 1", "Entry 2"]

© unyt 2024 • unyt.org