Created
July 6, 2017 07:52
-
-
Save dan-ste/3614d41319a6c4fd5b3c00fda3c324ad 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
export default TutorialComponent.extend({ | |
result: null, | |
isFindingStores: false, // Add a Loading Spinner | |
actions: { | |
findStores() { | |
if (this.isFindingStores) { return; } // Preventing Concurrency | |
let geolocation = this.get('geolocation'); | |
let store = this.get('store'); | |
this.set('isFindingStores', true); // Add a Loading Spinner | |
geolocation.getCoords() | |
.then(coords => store.getNearbyStores(coords)) | |
.then(result => { | |
if (this.isDestroyed) { return; } // Handling "set on destroyed object" errors | |
this.set('result', result); | |
}) | |
.finally(() => { // Handle promise rejection | |
if (this.isDestroyed) { return; } | |
this.set('isFindingStores', false); // Add a Loading Spinner | |
}); | |
} | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment