Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.
/ vuex-reset Public archive
forked from ianwalter/vuex-reset

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

License

Notifications You must be signed in to change notification settings

softzer0/vuex-reset

 
 

Repository files navigation

@ianwalter/vuex-reset

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

npm page

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

License

Apache 2.0 with Commons Clause - See LICENSE

 

Created by Ian Walter

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 53.9%
  • Vue 40.7%
  • HTML 4.4%
  • CSS 1.0%