Skip to content

Instantly share code, notes, and snippets.

@chrisbraddock
Last active March 11, 2020 17:39
Show Gist options
  • Save chrisbraddock/8ab64f6862941ec131a1f800afeaa980 to your computer and use it in GitHub Desktop.
Save chrisbraddock/8ab64f6862941ec131a1f800afeaa980 to your computer and use it in GitHub Desktop.
Use the config below to plop Vuex modules. Plop - https://github.com/amwmedia/plop
$ npm i -g plop
$ npm i --save-dev plop
// install the plopfile below
// install the template below
$ plop store:module
// repo root/plopfile.js:
module.exports =
function(plop) {
plop.setGenerator('store:module', {
description: 'make a new store module',
prompts: [{
type: 'input',
name: 'moduleName',
message: 'module name',
validate: function (value) {
if ((/.+/).test(value)) return true
return 'module name is required'
}
}],
actions: [{
type: 'add',
path: 'src/store/modules/{{dashCase moduleName}}.js',
templateFile: 'templates/store/module.js'
}, {
type: 'add',
path: 'src/store/actions/{{dashCase moduleName}}.js',
template: 'export default {}'
}]
})
}
// repo root/templates/store/modules.js:
import { } from '../types'
import actions from '../actions/{{dashCase moduleName}}'
import { log } from '../../plugins/log'
import VuexFire from 'vuexfire'
const state = {}
// getters receive: ( { state, rootState, getters }, payload )
const getters = {}
let moduleMutations = VuexFire.moduleMutations('{{dashCase moduleName}}')
// mutations receive: ( state, payload )
const mutations = { ...moduleMutations, ...{} }
export default { actions, getters, mutations, state }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment