Created
February 24, 2016 11:41
-
-
Save Phunky/0229d371c9459d82cc21 to your computer and use it in GitHub Desktop.
This file contains 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 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