Skip to content

Instantly share code, notes, and snippets.

View dan-ste's full-sized avatar

Daniel Steshenko dan-ste

View GitHub Profile
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
for(var i = 0; i<=5; i++) {
setTimeout(function timer() {
console.log(i);
}, i*1000);
}
<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>
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);
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();
<button onclick={{perform findStores}}>
Find Nearby Stores
{{#if findStores.isRunning}}
{{! ++ }}
{{fa-icon "spinner" spin=true}}
{{/if}}
</button>
{{#if result}}
{{#each result.stores as |s|}}
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');
@dan-ste
dan-ste / production-ready.js
Created July 6, 2017 07:50
Production ready
export default TutorialComponent.extend({
result: null,
isFindingStores: false,
actions: {
findStores() {
if (this.isFindingStores) { return; }
let geolocation = this.get('geolocation');
let store = this.get('store');
@dan-ste
dan-ste / bare-minimum.hbs
Created July 6, 2017 07:35
Bare-minimum
<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>
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 => {