Created
July 9, 2017 20:58
-
-
Save xtrasmal/30a0ff840c6b197afb2e754793fe09ed to your computer and use it in GitHub Desktop.
Setup of my Vuex store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('./setup'); | |
import {store} from './store'; | |
/* | |
Root components: | |
all root components below are merely dummies | |
*/ | |
// Sitebuilder root component | |
if(elementIsFound("sitebuilder")) { | |
const Sitebuilder = Vue.component('sitebuilder', require('./components/sitebuilder')); | |
new Vue({ | |
store, | |
components: { Sitebuilder } | |
}).$mount('#sitebuilder'); | |
} | |
// Medialibrary root component | |
if(elementIsFound("medialibrary")) { | |
const MediaLibrary = Vue.component('medialibrary', require('./components/medialibrary')); | |
new Vue({ | |
store, | |
components: { MediaLibrary } | |
}).$mount('#medialibrary'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.Vue = require('vue'); | |
window.axios = require('axios'); | |
window.flasher = require('./helpers/flasher'); | |
window._ = require('lodash'); | |
window.$ = window.jQuery = require('jquery'); | |
window.Bus = new Vue(); | |
// AXIOS | |
let token = document.head.querySelector('meta[name="csrf-token"]'); | |
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; | |
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content; | |
// HELPERS | |
window.log = (something) => {return console.log(something)}; | |
window.base64Decode = (obj) => {return JSON.parse(atob(obj))}; | |
window.base64Encode = (obj) => {return btoa(JSON.stringify(obj))}; | |
window.elementIsFound = (element) => {return document.body.contains(document.getElementById(element))}; | |
// ARRAY extra's | |
Array.prototype.move = function(from, to) { | |
this.splice(to,0,this.splice(from,1)[0]); | |
return this; | |
}; | |
/** | |
* Default Actions | |
* get: {method: 'GET'} | |
* save: {method: 'POST'} | |
* query: {method: 'GET'} | |
* update: {method: 'PUT'} | |
* delete: {method: 'DELETE'} | |
* | |
* @param path the resource path | |
* @param http axios instance | |
* @param actions custom actions | |
* @returns the resource object | |
*/ | |
window.resource = (path, http, actions) => { | |
let obj = { | |
all: id => http.get(path), | |
get: id => http.get(path + '/' + id), | |
save: obj => http.post(path, obj), | |
query: params => http.get(path, {params}), | |
update: (id, obj) => http.put(path + '/' + id, obj), | |
delete: id => http.delete(path + '/' + id) | |
}; | |
return Object.assign(obj, actions); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue'; | |
import Vuex from 'vuex'; | |
import { mapGetters } from 'vuex'; | |
import InterfaceStoreModule from './store/modules/interface'; | |
import MediaLibraryStoreModule from './store/modules/medialibrary'; | |
import NavigationStoreModule from './store/modules/navigation'; | |
import SiteBuilderStoreModule from './store/modules/sitebuilder'; | |
Vue.use(Vuex); | |
window.getters = mapGetters; | |
const store = new Vuex.Store({ | |
strict: process.env.NODE_ENV !== 'production' | |
}); | |
/* | |
Store modules: | |
Register here OR register somewhere else, when getters start biting or whatever. | |
example: this.$store.registerModule('interface', InterfaceStoreModule); | |
*/ | |
store.registerModule('interface', InterfaceStoreModule); | |
store.registerModule('medialibrary', MediaLibraryStoreModule); | |
store.registerModule('navigation', NavigationStoreModule); | |
store.registerModule('sitebuilder', SiteBuilderStoreModule); | |
export default store; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment