https://github.com/unyt-org/example-history-api
A example project to showcase the DATEX history API
https://github.com/unyt-org/example-history-api
datex pointers typescript uix uix-example unyt
Last synced: 3 months ago
JSON representation
A example project to showcase the DATEX history API
- Host: GitHub
- URL: https://github.com/unyt-org/example-history-api
- Owner: unyt-org
- License: mit
- Created: 2024-04-04T11:46:29.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-16T17:18:27.000Z (8 months ago)
- Last Synced: 2025-03-07T17:22:28.965Z (3 months ago)
- Topics: datex, pointers, typescript, uix, uix-example, unyt
- Language: CSS
- Homepage: https://history.example.unyt.org
- Size: 8.79 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DATEX History API Example
This is a example project demonstrating how to use the [History API](https://docs.unyt.org/manual/datex/history) 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:```ts
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:
```ts
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](https://unyt.org)