@ianwalter/vuex-reset

A Vuex plugin that makes restoring initial state to the store simple
17,510 26
Install
npm install @ianwalter/vuex-reset
Latest Version:4.3.4
Vue:2
License:Custom
Last Updated:Aug 8, 2023
Links: GitHub  ·  npm
Maintainer: ianwalter

@ianwalter/vuex-reset

A Vuex plugin that makes restoring initial state to the store simple

npm page CI

Resources

Installation

pnpm add @ianwalter/vuex-reset

Usage

import VuexReset from '@ianwalter/vuex-reset'

const store = new Vuex.Store({
  plugins: [VuexReset()],
  state: {
    message: 'Welcome!',
    mutations: {
      // A no-op mutation must be added to serve as a trigger for a reset. The
      // name of the trigger mutation defaults to 'reset' but can be specified
      // in options, e.g. VuexReset({ trigger: 'data' }).
      reset: () => {}
    }
  }
})

// Reset the store to it's initial state.
store.commit('reset')

You can also reset a namespaced module to it's initial state, for example:

const store = new Vuex.Store({
  plugins: [VuexReset()],
  state: {
    message: 'Welcome!'
  },
  modules: {
    car: {
      namespaced: true,
      state: {
        brand: 'Honda'
      },
      mutations: {
        reset: () => {}
      }
    }
  }
})

// Reset the car module to it's initital state.
store.commit('car/reset')

Related

  • vue-component-reset - A Vue.js component mixin that makes restoring initial state to the component simple

@ianwalter/vuex-reset for enterprise

Available as part of the Tidelift Subscription

The maintainers of @ianwalter/vuex-reset and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

License

Hippocratic License - See LICENSE

 

Created by Ian Walter

Related Packages

vuex-extensions

Add Reset and Mixins function to Vuex

170,780 40
@harlem/extension-reset

The official reset extension for Harlem

1,275 515
vuex-dry

DRY vuex, no more repetitive codes

2,136 51
vue-save-state

A Vue mixin to save the state of a component to local storage

20,561 243
vuex-stateshot

A state snapshot plugin on actions/mutations for Vuex3.1+.

2,201 12

Version History

Version Released License
4.3.4 Custom
4.3.3 Custom
4.3.2 Custom
4.3.1 Custom
4.3.0 Custom
Pre-releases (1)
Version Released License
2.1.3-0 Custom