Skip to content

Instantly share code, notes, and snippets.

@vincentbello
Created October 8, 2016 19:44
Show Gist options
  • Save vincentbello/154d964440cec20b14f359fcf9e33d53 to your computer and use it in GitHub Desktop.
Save vincentbello/154d964440cec20b14f359fcf9e33d53 to your computer and use it in GitHub Desktop.
components/product-overview.js
// 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(() => {
if (this.get('product')) {
this.get('product').reload();
}
}, 30 * 1000);
this._super(...arguments);
},
// Stop timer when component is destroyed
willDestroyElement() {
this._super(...arguments);
this.get('timer').stop();
},
actions: {
cancelReloadTask() {
this.get('timer').stop();
},
restartReloadTask() {
this.get('timer').start(() => ...);
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment