Skip to content

Instantly share code, notes, and snippets.

@dan-ste
Created July 6, 2017 07:52
Show Gist options
  • Save dan-ste/3614d41319a6c4fd5b3c00fda3c324ad to your computer and use it in GitHub Desktop.
Save dan-ste/3614d41319a6c4fd5b3c00fda3c324ad to your computer and use it in GitHub Desktop.
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