2.2.9 • Published 4 years ago

history-handler v2.2.9

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Introduction

Handles your undo and redo, customizable to your liking

Usage & Demo

GitHub Release

  1. Place this line on your template file:

    <script src="https://github.com/RinMinase/history-handler/releases/latest/download/history-handler.min.js"></script>

NPM

  1. You can install history-handler using npm

    npm install history-handler
  2. Add it on your module, like so

    /** For JavaScript */
    const history = require("history-handler");
    /** For TypeScript */
    import history from "history-handler";
  3. 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 done
  • undo array buffer - contains the previous actions being done
  • redo 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 of 10
  • 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 types object | 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

2.2.9

4 years ago

2.2.8

4 years ago

2.2.7

4 years ago

2.2.6

4 years ago

2.2.5

4 years ago

2.2.4

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.1.11

4 years ago

2.1.10

4 years ago

2.1.9

4 years ago

2.1.8

4 years ago

2.1.5

4 years ago

2.1.4

4 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

1.0.1

4 years ago

2.0.0

4 years ago

1.0.0

4 years ago

0.1.0

4 years ago