Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Steshenko dan-ste

View GitHub Profile
View controllers.application.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
View gist:1f34ecd204bfeef220f0f8f8b238dc67
for(var i = 0; i<=5; i++) {
setTimeout(function timer() {
console.log(i);
}, i*1000);
}
View result.hbs
<button onclick={{perform findStores}}>
Find Nearby Stores
{{#if findStores.isRunning}}
{{fa-icon "spinner" spin=true}}
{{/if}}
</button>
{{#if result}}
{{#each result.stores as |s|}}
<li>
View gist:47c1eda47ef95508a6e8cb06a4c3f811
export default TutorialComponent.extend({
result: null,
findStores: task(function * () {
let geolocation = this.get('geolocation');
let store = this.get('store');
try() {
let coords = yield geolocation.getCoords();
let result = yield store.getNearbyStores(coords);
this.set('result', result);
View prevent-concurrency.js
import { task } from 'ember-concurrency';
export default TutorialComponent.extend({
result: null,
findStores: task(function * () {
let geolocation = this.get('geolocation');
let store = this.get('store');
let coords = yield geolocation.getCoords();
View loading-state.hbs
<button onclick={{perform findStores}}>
Find Nearby Stores
{{#if findStores.isRunning}}
{{! ++ }}
{{fa-icon "spinner" spin=true}}
{{/if}}
</button>
{{#if result}}
{{#each result.stores as |s|}}
View production-ready.js
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');
View production-ready.js
export default TutorialComponent.extend({
result: null,
isFindingStores: false,
actions: {
findStores() {
if (this.isFindingStores) { return; }
let geolocation = this.get('geolocation');
let store = this.get('store');
View bare-minimum.hbs
<button onclick={{action 'findStores'}}>
Find Nearby Stores
</button>
{{#if result}}
{{#each result.stores as |s|}}
<li>
<strong>{{s.name}}</strong>:
{{s.distance}} miles away
</li>
View bare-minimum.js
export default TutorialComponent.extend({
result: null,
actions: {
findStores() {
let geolocation = this.get('geolocation');
let store = this.get('store');
geolocation.getCoords()
.then(coords => store.getNearbyStores(coords))
.then(result => {