@lucy2/undoredo
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

undoredo

Install

npm i @lucy2/undoredo

Usage

<script setup lang="ts">
import UndoRedo from "@lucy2/undoredo";
import { ref } from "vue"
const input = ref(0);

let undoredo = new UndoRedo(function change() {
  console.log("change handler")
});


undoredo.registry({
  name: "update",
  pushQueue: true,
  init(){
   //init
   return ()=>{
      //destroy
   }
  },
  execute(newValue: number, oldValue: number) {
    let state = {
      before: oldValue,
      after: newValue
    }
    return {
      undo() {
        input.value = state.after
      },
      redo() {
        input.value = state.before;
      }

    }
  }
})
const descrease = () => undoredo.state.commands.update(Number(input.value) - 1, Number(input.value))
const increase = () => undoredo.state.commands.update(Number(input.value) + 1, Number(input.value))
</script>

<template>
  <div>
    <input placeholder="input" :value="input" disabled>
    <button @click="descrease">--</button>
    <button @click="increase">++</button>

    <button @click="undoredo.state.commands.redo();">undo</button>
    <button @click="undoredo.state.commands.undo();">redo</button>
  </div>
</template>

<style scoped>

undoredo

undoredo

Readme

Keywords

Package Sidebar

Install

npm i @lucy2/undoredo

Weekly Downloads

2

Version

0.0.8

License

none

Unpacked Size

8.95 kB

Total Files

6

Last publish

Collaborators

  • lucy2