a simple web player for subsonic tinysub.devins.page
subsonic navidrome javascript
9
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: implement basic 2-stack undo-redo

this is quite basic, uses a snapshot style history instead of a
command-style storage, where we could store forward/reverse callbacks.

as a result, this can presently only be used for storing and loading
full snapshots. you cannot undo favourites/ratings with this model.

to improve this, i would probably update this down the line to make each
item of the undostack store a:

{forwardOp, reverseOp}

and the queue snapshotting logic can be augmented to simply be:

{() => {return newState;}, () => {return oldState;}}

Signed-off-by: oppiliappan <me@oppi.li>

authored by

oppiliappan and committed by
Tangled
64c562ed 6ac918f7

+35
+35
src/js/history.js
··· 1 + class History { 2 + constructor() { 3 + this.undoStack = new BoundedStack(32); 4 + this.redoStack = new BoundedStack(32); 5 + } 6 + 7 + saveState(snapshot) { 8 + this.undoStack.push(snapshot); 9 + this.redoStack.clear(); 10 + } 11 + 12 + undo(currentSnapshot) { 13 + if (this.undoStack.isEmpty()) return null; 14 + 15 + // save current state to redo stack before undoing 16 + if (currentSnapshot) { 17 + this.redoStack.push(currentSnapshot); 18 + } 19 + 20 + return this.undoStack.pop(); 21 + } 22 + 23 + redo(currentSnapshot) { 24 + if (this.redoStack.isEmpty()) return null; 25 + 26 + // save current state to undo stack before redoing 27 + if (currentSnapshot) { 28 + this.undoStack.push(currentSnapshot); 29 + } 30 + 31 + return this.redoStack.pop(); 32 + } 33 + } 34 + 35 + const history = new History();