1
0
Fork 0

Proper dispatch events, error handling

This commit is contained in:
Joe Wroten 2017-05-07 20:58:36 -04:00
parent 85492f8a6e
commit 25e6af91c8
2 changed files with 37 additions and 13 deletions

View file

@ -13,9 +13,9 @@
</template> </template>
<script> <script>
import { Loading } from 'quasar' import { Loading, Dialog } from 'quasar'
import Vue from 'vue' import Vue from 'vue'
import { state } from '../store' import { state, dispatch } from '../store'
import SpellList from './Spelllist' import SpellList from './Spelllist'
import 'whatwg-fetch' import 'whatwg-fetch'
@ -30,18 +30,29 @@ export default {
mounted () { mounted () {
if (this.state.spells.loaded === false) { if (this.state.spells.loaded === false) {
Loading.show() Loading.show()
}
fetch('./statics/dnd5e.json') fetch('./statics/dnd5e.json')
.then(response => response.json()) .then(response => response.json())
.then(spells => { .then(spells => {
this.state.spells = { dispatch({
loaded: true, type: 'SPELLS_RESOLVED',
data: spells data: {
} loaded: true,
Loading.hide() data: spells
}) }
.catch(reason => console.error('Unable to retrieve spells list:', reason)) })
})
.catch(reason => {
let message = 'Unable to retrieve spells list'
Dialog.create({
title: 'Error',
message,
nobuttons: true
})
console.error(message, reason)
})
.then(() => { Loading.hide() })
}
} }
} }
</script> </script>

View file

@ -4,3 +4,16 @@ export let state = {
data: [] data: []
} }
} }
export function dispatch (action) {
switch (action.type) {
case 'SPELLS_RESOLVED':
state.spells = action.data
break
}
}
export default {
state,
dispatch
}