diff options
author | Elizabeth Hunt <me@liz.coffee> | 2025-06-14 18:54:05 -0700 |
---|---|---|
committer | Elizabeth Hunt <me@liz.coffee> | 2025-06-14 18:54:05 -0700 |
commit | c31e481a0776b7b696cb13ff6260831b0d527018 (patch) | |
tree | 9e8c167007b8269ac572d5ae0ddd1dd8765c43b2 | |
parent | 55519c21af02b344fa9753111e3bf6f4975b0479 (diff) | |
download | ci-c31e481a0776b7b696cb13ff6260831b0d527018.tar.gz ci-c31e481a0776b7b696cb13ff6260831b0d527018.zip |
Add history to pengueno
-rw-r--r-- | u/history.ts | 36 | ||||
-rw-r--r-- | u/mod.ts | 1 |
2 files changed, 37 insertions, 0 deletions
diff --git a/u/history.ts b/u/history.ts new file mode 100644 index 0000000..5b13961 --- /dev/null +++ b/u/history.ts @@ -0,0 +1,36 @@ +export interface History<T> { + undo: () => History<T> | undefined; + redo: () => History<T> | undefined; + + get: () => T; + add: (value: T) => History<T>; +} + +export class HistoryImpl<T> implements History<T> { + private readonly item: T; + private previous?: History<T>; + private next?: History<T>; + + constructor(item: T) { + this.item = item; + } + + public get(): T { + return this.item; + } + + public undo(): History<T> | undefined { + return this.previous; + } + + public redo(): History<T> | undefined { + return this.next; + } + + public add(value: T): History<T> { + const newHistory = new HistoryImpl(value); + newHistory.previous = this; + this.next = newHistory; + return newHistory; + } +} @@ -3,3 +3,4 @@ export * from "./leftpadesque/mod.ts"; export * from "./process/mod.ts"; export * from "./trace/mod.ts"; export * from "./server/mod.ts"; +export * from "./history.ts"; |