history-handler
TypeScript icon, indicating that this package has built-in type declarations

2.2.9 • Public • Published

History Handler

Circle-CI   Semantic-Release

Bundle-Phobia   NPM-DM Coverage

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

Package Sidebar

Install

npm i history-handler

Weekly Downloads

2

Version

2.2.9

License

MIT

Unpacked Size

44.5 kB

Total Files

15

Last publish

Collaborators

  • rinminase