Skip to content

Instantly share code, notes, and snippets.

@Phunky
Created February 24, 2016 11:41
Show Gist options
  • Save Phunky/0229d371c9459d82cc21 to your computer and use it in GitHub Desktop.
Save Phunky/0229d371c9459d82cc21 to your computer and use it in GitHub Desktop.
import Vuex from 'vuex'
import Vue from 'vue'
import _ from 'lodash'
import store from 'store'
import auth from './auth'
import config from '../config'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
meta: null,
loaded: false,
employees: [],
},
mutations: {
LOADED_EMPLOYEES (state, response) {
state.employees = response.data
state.meta = response.meta
},
ALL_EMPLOYEES_LOADED (state) {
state.loaded = true;
}
},
actions: {
load ({ actions, _vm, dispatch, state }) {
var uri = config.api + '/employee';
if( state.meta ) {
if( !state.meta.pagination.links.next ) {
return dispatch('ALL_EMPLOYEES_LOADED');
}
uri = state.meta.pagination.links.next
}
_vm.$http
.get( uri, {}, {} )
.then( function(response) {
dispatch('LOADED_EMPLOYEES', response.data);
actions.load(arguments);
} )
.catch(function(response){
console.log(response)
})
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment