history-handler
v2.2.9
Published
Handles your undo and redo, customizable to your liking
Downloads
17
Maintainers
Readme
Introduction
Handles your undo and redo, customizable to your liking
Usage & Demo
GitHub Release
Place this line on your template file:
<script src="https://github.com/RinMinase/history-handler/releases/latest/download/history-handler.min.js"></script>
NPM
You can install history-handler using npm
npm install history-handler
Add it on your module, like so
/** For JavaScript */ const history = require("history-handler");
/** For TypeScript */ import history from "history-handler";
Use it in your code, like so
// Initialize the history history(); // Add some actions to the buffer history.action("action"); history.action("another action"); const buffer = history.buffer(); // variable would be "another action" const action = history.undo(); // variable would be "another action" buffer = history.getBuffer(); // variable would be "action" const redo = history.redo(); // variable would be "another action"
How it works
This library contains 1 buffer and 2 array buffers to hold your objects for managing history.
buffer
- contains the current action being doneundo array buffer
- contains the previous actions being doneredo array buffer
- contains the actions after using undo
What each method does:
(constructor) history(buffer_length: number)
- The
buffer_length
indicates the limit of the undo and redo buffers - Has a
default value
of10
- If new items go beyond the stated length, the lowest item in the buffer would be removed
Action(item: object | string | number)
- Pushes the current buffer to the undo stack
- Pushes the
item
of typesobject | string | number
to the buffer
Undo: object | string | number
- Pushes the current buffer to the redo stack
- Pops out the last element of the undo stack
- Places the last element in the current buffer
- Returns the buffer
Redo: object | string | number
- Pushes the current buffer to the undo stack
- Pops out the last element of the redo stack
- Places the last element in the current buffer
- Returns the buffer
Clear: void
- Clears all the buffers
GetBuffer: object | string | number
- Returns the current buffer
GetUndoBuffer: Array < object | string | number >
- Returns the undo array buffer
GetRedoBuffer: Array < object | string | number >
- Returns the redo array buffer
Built with
- NodeJS - Library setup
- Circle CI - Continuous Integration (CI) service
- Semantic Release📦🚀 - Releasing strategy