Skip to content

Reset store to its initial state? #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
NikitaKA opened this issue Apr 16, 2019 · 3 comments
Closed

Reset store to its initial state? #21

NikitaKA opened this issue Apr 16, 2019 · 3 comments

Comments

@NikitaKA
Copy link

Hi! Is it possible to do something like that (vuejs/vuex#1118 (comment)) in this module?

@ktsn
Copy link
Owner

ktsn commented Apr 16, 2019

Essentially same as Vuex.

class FooState {
  /* ... */
}

class FooMutations extends Mutations<FooState> {
  reset () {
      // acquire initial state
      const s = new FooState()
      Object.keys(s).forEach(key => {
        this.state[key] = s[key]
      })
  }
}

@ktsn ktsn closed this as completed Apr 16, 2019
@davidreyg
Copy link

Ir works. But how could i deal with typescript? Any solution?

@temyer
Copy link

temyer commented Mar 29, 2022

reset(): void {
  const s = new FooState();
  type k = keyof FooState;

  (Object.keys(s) as Array<k>).forEach((key) => {
    (this.state[key] as FooState[k]) = s[key];
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants