History Handler
Introduction
Handles your undo and redo, customizable to your liking
Usage & Demo
GitHub Release
-
Place this line on your template file:
NPM
-
You can install history-handler using npm
npm install history-handler -
Add it on your module, like so
/** For JavaScript */const history = ;/** For TypeScript */; -
Use it in your code, like so
// Initialize the history;// Add some actions to the bufferhistoryaction"action";historyaction"another action";const buffer = history;// variable would be "another action"const action = history;// variable would be "another action"buffer = history;// variable would be "action"const redo = history;// 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