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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
items: ['hello', 'world'], | |
displayedItems: Ember.computed('visibilityMap', 'items', function () { | |
const visibilityMap = this.get('visibilityMap'); | |
const items = this.get('items'); | |
return items.filter(item => { |
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
// Callback functions | |
function fetchData() { | |
this.fetch('data', (data) => { | |
this.updateUI(); | |
}); | |
} | |
// Promises | |
function fetchData() { | |
this.fetch('data') |
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 Ember.Route.extend({ | |
/** Use the url params to fetch the model data */ | |
model(params) { | |
if (!Ember.isEmpty(params.products)) { | |
return params.products.map((product) => { | |
return { | |
name: product, | |
taskInstance: this.get('findProductTask').perform(product), | |
}; | |
}); |
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
import Ember from 'ember'; | |
import { task, timeout } from 'ember-concurrency'; | |
export default Ember.Component.extend({ | |
// Periodically refresh product info on init | |
_reloadDataTask: task(function * () { | |
while (true) { | |
yield timeout(30 * 1000); // Wait 30 seconds | |
if (this.get('product')) { |
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
// components/product-overview.js | |
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
timer: Ember.inject.service(), | |
// Periodically refresh product info | |
init() { | |
this.get('timer').start(() => { |
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
// General purpose timer service | |
import Ember from 'ember'; | |
export default Ember.Service.extend({ | |
interval: 5000, | |
// Schedules function `f` to be executed on interval | |
schedule(f, interval) { | |
const time = interval || this.get('interval'); | |
return Ember.run.later(this, function() { |