Created
October 8, 2016 19:44
-
-
Save vincentbello/154d964440cec20b14f359fcf9e33d53 to your computer and use it in GitHub Desktop.
components/product-overview.js
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(() => { | |
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