1
0
Fork 0

Code cleanup

This commit is contained in:
Joe Wroten 2017-05-14 05:20:21 -05:00
parent 2fba3427cc
commit 89ca44069b

View file

@ -30,6 +30,26 @@ import SpellList from './Spelllist'
Vue.component('spell-list', SpellList) Vue.component('spell-list', SpellList)
function fetchSuccess (data) {
dispatch({
type: 'SPELLS_RESOLVED',
data: {
data,
loaded: true
}
})
}
function fetchFailure (reason) {
let message = 'Unable to retrieve spells list'
Dialog.create({
title: 'Error',
message,
nobuttons: true
})
console.error(message, reason)
}
export default { export default {
data () { data () {
return { return {
@ -43,24 +63,8 @@ export default {
fetch('./statics/dnd5e.json') fetch('./statics/dnd5e.json')
.then(response => response.json()) .then(response => response.json())
.then(spells => { .then(fetchSuccess)
dispatch({ .catch(fetchFailure)
type: 'SPELLS_RESOLVED',
data: {
loaded: true,
data: spells
}
})
})
.catch(reason => {
let message = 'Unable to retrieve spells list'
Dialog.create({
title: 'Error',
message,
nobuttons: true
})
console.error(message, reason)
})
.then(() => { Loading.hide() }) .then(() => { Loading.hide() })
} }
} }