From 4bc780406775a32739e486e9a57cce9b8a77ecd5 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 25 Jan 2020 14:51:38 +0100 Subject: [PATCH] promisify getChannels action to wait before calling getVideos --- src/App.vue | 5 +++-- src/store/actions.js | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/App.vue b/src/App.vue index e0c499f..a1ef313 100644 --- a/src/App.vue +++ b/src/App.vue @@ -33,8 +33,9 @@ export default { ]), async created() { - this.$store.dispatch('getChannels'); - this.$store.dispatch('getVideos'); + this.$store.dispatch('getChannels').then(() => { + this.$store.dispatch('getVideos'); + }); }, }; diff --git a/src/store/actions.js b/src/store/actions.js index 476e312..9b477ba 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -13,7 +13,12 @@ export default { }, async getChannels({ commit }) { - commit(types.GET_CHANNELS, await database.channels.toArray()); + return new Promise((resolve) => { + database.channels.toArray().then((result) => { + commit(types.GET_CHANNELS, result); + resolve(); + }); + }); }, selectChannel({ commit, dispatch }, index) {