From 21e902053cba7126146011b6e55d58dbe46821b7 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Tue, 26 Feb 2019 18:58:33 +0000 Subject: [PATCH] Streamlined autofocus code There now aren't any nested promises at the top level. I think we should be able to get rid of the ones in the store.dispatch method too, but that bothers me less because I can't see it! --- src/components/paneNavigate.vue | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/components/paneNavigate.vue b/src/components/paneNavigate.vue index e665dc54..2f7b15cd 100644 --- a/src/components/paneNavigate.vue +++ b/src/components/paneNavigate.vue @@ -218,28 +218,22 @@ export default { if (!this.$store.state.moveLock) { // Lock move requests this.$store.commit('changeMoveLock', true); + this.isAutofocusing = true axios.post(this.autofocusApiUri, {dz: dz}) .then(response => { console.log("Autofocus Task ID: " + response.data[0].id) - this.isAutofocusing = true // Start the store polling TaskId for success - self = this; - this.$store.dispatch('pollTask', [response.data[0].id, null, null]) - .then(function() { - UIkit.notification({message: "Finished recalibration.", status: 'success'}) - }) - .catch(error => { - UIkit.notification({message: ` ${error}`, status: 'danger'}) - }) - .finally(() => { - self.isAutofocusing = false - this.$store.commit('changeMoveLock', false) // Release the move lock - }) + return this.$store.dispatch('pollTask', [response.data[0].id, null, null]) }) + .then(() => { console.log("Successfully finished autofocus"); }) .catch(error => { + UIkit.notification({message: ` ${error}`, status: 'danger'}) this.$store.dispatch('handleHTTPError', error); // Let store handle error - self.isAutofocusing = false - this.$store.commit('changeMoveLock', false) // Release the move lock + }) + .finally(() => { + console.log("Cleaning up after autofocus.") + this.isAutofocusing = false; + this.$store.commit('changeMoveLock', false); // Release the move lock }) } }