Skip to content
A Vuex plugin that makes restoring initial state to the store simple
JavaScript Vue HTML CSS
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Updating CI triggers Oct 28, 2019
site Fixing webpack plugin Jul 20, 2019
.gitignore Adding rclone.conf Aug 27, 2019
LICENSE
README.md
index.js Bugfix: targeting modules containing slash in name Sep 17, 2019
package.json Update dependency @ianwalter/bff to ^8.1.0 Jan 18, 2020
rclone.conf Adding rclone.conf Aug 27, 2019
tests.js Bugfix: targeting modules containing slash in name Sep 17, 2019
webpack.config.js Fixing webpack plugin Jul 20, 2019
yarn.lock Update dependency @ianwalter/bff to ^8.1.0 Jan 18, 2020

README.md

@ianwalter/vuex-reset

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

npm page CI

Resources

Installation

yarn 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

You can’t perform that action at this time.