0.2.4 • Published 5 months ago

pinia-undo v0.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

pinia-undo

Enable time-travel in your apps. Undo/Redo plugin for pinia.

Requires Vue ^2.6.14 || ^3.2.0

Install

pnpm add pinia pinia-undo

Usage

import { PiniaUndo } from 'pinia-undo'

const pinia = createPinia()
pinia.use(PiniaUndo)

This adds undo and redo properties to your stores.

const useCounterStore = defineStore({
  id: 'counter',
  state: () => ({
    count: 10,
  }),
  actions: {
    increment() {
      this.count++
    },
  },
})

const counterStore = useCounterStore()

// undo/redo have no effect if we're at the
// beginning/end of the stack
counterStore.undo() // { count: 10 }
counterStore.redo() // { count: 10 }

counterStore.increment() // { count: 11 }
counterStore.increment() // { count: 12 }

counterStore.undo() // { count: 11 }
counterStore.undo() // { count: 10 }
counterStore.undo() // { count: 10 }

counterStore.redo() // { count: 11 }

Options

NameTypeDefaultDescription
omitarray[]An array of fields that the plugin will ignore.
disablebooleanfalseDisable history tracking of store.
serializerobject{ serializer: JSON.stringify, deserializer: JSON.parse }Custome serializer to serialize state before storing it in the undo stack.
const useCounterStore = defineStore({
  id: 'counter',
  state: () => ({
    count: 10,
    name: 'John Doe',
  }),
  undo: {
    omit: ['name'],
  },
})

License

MIT.

0.2.4

5 months ago

0.2.1

5 months ago

0.2.2

5 months ago

0.2.0

11 months ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.9

1 year ago

0.1.6

1 year ago

0.1.5

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.0.3

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago