question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I reset vuex store to initial state? normally without VuexModule I can reset store easily like this:

// default state
const getDefaultState = () => ({
    name: 'example',
    age: 20
})

// store
const store = new Vuex.Store({
    state: getDefaultState(),
    mutations: {
        resetState(state) {
            Object.assign(state, getDefaultState())
        }
    }
})

But I can’t figure out how could I achieve this with vuex-module-decorators

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

4reactions
delowardevcommented, Jul 8, 2020

Hey @delowardev did you managed to fix this?

@bangjelkoski Yes, very simple solution:

const defaultState = {
   firstName: "John",
   lastName: "Doe"
};

@Module({ name: "example", namespaced: true })
export default class ExampleModule extends VuexModule {
   firstName = defaultState.firstName;
   lastName = defaultState.lastName;

  @Mutation
  resetState() {
       this.firstName = defaultState.firstName;
       this.lastName = defaultState.lastName;
  }
}
2reactions
delowardevcommented, May 17, 2021

@bill-lee-aics if there are many states, a loop could be helpful. for example:

@Mutation
resetState() {
  Object.keys(defaultState).forEach(key => {
      this[key] = defaultState[key];
  })
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

The Reset | Elevated Essentials Edited For Effortlessness
The Reset offers versatile, flattering, modern go-tos that make dressing easy so you look and feel your best. Elevated essentials that are designed...
Read more >
Reset Vintage Apparel BUY • SELL • TRADE – Reset Web Store
RESET STL 2607 Bellevue Ave Maplewood, MO 314.833.3061 @Reset_STL. RESET KC 8 Westport Rd Kansas City, MO 816.299.9941
Read more >
What's the Difference between a Store Reset and a Store ...
A store Reset is the process of rearranging/replacing fixtures, shelves, stand-alone units, merchandise etc., ultimately to make a retail business more ...
Read more >
Reset STL (@reset_stl) • Instagram photos and videos
Reset STL. Buy ♦️ Sell ♦️ Trade Monday-Saturday • 12-7pm. Sunday • 12-5pm. resetvtg.com. 2,226 posts. 49.4K followers. 105 following.
Read more >
How to Reset Microsoft Store or Clear Windows Store Cache
To reset Microsoft Store, open Settings > Apps > Apps and features > Search for Microsoft Store > Advanced options > Use the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found