• Stars
    star
    174
  • Rank 219,104 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Undo/Redo plugin for Vuex

vuex-undo-redo

A Vue.js plugin that allows you to undo or redo a mutation.

The building of this plugin is documented in the article Create A Vuex Undo/Redo For VueJS

Live demos

Edit Vuex Undo/Redo

There's also a demo in this Codepen. The source code for the demo is here.

Installation

npm i --save-dev vuex-undo-redo

Browser

<script type="text/javascript" src="node_modules/vuex-undo-redo/dist/vuex-undo-redo.min.js"></script>

Module

import VuexUndoRedo from 'vuex-undo-redo';

Usage

Since it's a plugin, use it like:

Vue.use(VuexUndoRedo);

You must, of course, have the Vuex plugin installed as well, and it must be installed before this plugin. You must also create a Vuex store which must implement a mutation emptyState which should revert the store back to the initial state e.g.:

new Vuex.Store({
  state: {
    myVal: null
  },
  mutations: {
    emptyState() {
      this.replaceState({ myval: null });       
    }
  }
});

Ignoring mutations

Occasionally, you may want to perform mutations without including them in the undo history (say you are working on an image editor and the user toggles grid visibility - you probably do not want this in undo history). The plugin has an ignoredMutations setting to leave these mutations out of the history:

Vue.use(VuexUndoRedo, { ignoreMutations: [ 'toggleGrid' ]});

It's worth noting that this only means the mutations will not be recorded in the undo history. You must still manually manage your state object in the emptyState mutation:

emptyState(state) {
  this.replaceState({ myval: null, showGrid: state.showGrid });       
}

API

Options

ignoredMutations an array of mutations that the plugin will ignore

Computed properties

canUndo a boolean which tells you if the state is undo-able

canRedo a boolean which tells you if the state is redo-able

Methods

undo undoes the last mutation

redo redoes the last mutation

More Repositories

1

vue-laravel-crud

Full-stack Vue + Laravel + Axios CRUD example
PHP
380
star
2

vue-router-user-roles

A Vue.js plugin that protects routes based on user roles. Add your own authentication.
JavaScript
241
star
3

vue-clock-simple

Repo for the article How To Publish Your Vue.js Component On NPM
JavaScript
88
star
4

vue-js-laravel-ssr

Source code for the article "Server-Side Rendering With Laravel & Vue.js 2.5"
PHP
70
star
5

vue-casl-demo

Repo for the article "Managing User Permissions in a VueJS App"
JavaScript
60
star
6

vue-js-laravel-multi-ssr

Source code for the article "Advanced Server-Side Rendering With Laravel & Vue: Multi-Page App"
PHP
37
star
7

vue-cli-plugin-critical

JavaScript
29
star
8

vue-dynamic-import

Repo for the article "Build A Lazy-Load Router With Vue.js And The Latest Browser Features"
JavaScript
28
star
9

vue-web-component

An example web component createed with Vue CLI 3
Vue
18
star
10

fake-ssr-vue-laravel

Fake server-side rendering with Vue.js and Laravel
PHP
18
star
11

vue-single-file-js-components

JavaScript
12
star
12

vue-webpack-brunch

Comparison of Webpack and Brunch using Vue.js
JavaScript
11
star
13

hcwp-demo

Demo of HTML Critical Webpack Plugin
JavaScript
10
star
14

oldtime-cars-vue-laravel

PHP
10
star
15

vue-router-user-roles-demo

A demo of vue-router-user-roles plugin
JavaScript
9
star
16

vuex-undo-redo-example

Repo for the article "Create A Vuex Undo/Redo For VueJS"
JavaScript
6
star
17

vue-template-extension-loader

A Webpack loader for extending Vue templates
6
star
18

liveframe

Javascript library to help with manipulation of an iframe
JavaScript
6
star
19

vue-course

Vue
6
star
20

awesomer-vue

Vue
4
star
21

vuejs-chat

CSS
3
star
22

vue-apollo-hasura-infinite-scroll

JavaScript
1
star
23

vue3-component-library

JavaScript
1
star
24

react-course

Source code for the article Build an Online Course with React.
JavaScript
1
star
25

vue-vagrant-headless-chrome

Run Nightwatch E2E tests on headless chrome in a Vagrant box
Vue
1
star
26

statamic-courses-starter-kit

Antlers
1
star