Skip to content

Instantly share code, notes, and snippets.

View brospars's full-sized avatar

Benoit Rospars brospars

View GitHub Profile
@brospars
brospars / readme.md
Last active September 25, 2020 15:07
Generate CRUD mutations and actions for Vuex

Vuex can be quite repetitive to write generic mutations (arrays : set, add, update, delete, literals: update) for each state property. But it's important to keep track of changes inside the store.

So here's a way to generate generic mutations and associated actions :

// book-store.js
const state = {
  id: '',
  title: '',
  authors: [],
@brospars
brospars / readme.md
Created September 18, 2020 11:54
Reset Vuex state store

Reseting Vuex module to its original state could be tideous if you have to manually reset all values. So instead you could use a function to retrieve the default state.

const getDefaultState = () => {
  return {
    id: '',
    authors: []
  }
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.