Toggle polling in components when switching away from the tab

This commit is contained in:
Michael Lange
2018-03-06 14:16:43 -08:00
parent a6319f3fcb
commit 01de2ea257
2 changed files with 26 additions and 2 deletions

View File

@@ -2,8 +2,9 @@ import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { lazyClick } from '../helpers/lazy-click';
import { watchRelationship } from 'nomad-ui/utils/properties/watch';
import WithVisibilityDetection from 'nomad-ui/mixins/with-component-visibility-detection';
export default Component.extend({
export default Component.extend(WithVisibilityDetection, {
store: service(),
tagName: 'tr',
@@ -27,6 +28,17 @@ export default Component.extend({
}
},
visibilityHandler() {
if (!document.visible) {
this.get('watch').cancelAll();
} else {
const node = this.get('node');
if (node) {
this.get('watch').perform(node, 100);
}
}
},
willDestroy() {
this.get('watch').cancelAll();
this._super(...arguments);

View File

@@ -2,8 +2,9 @@ import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { lazyClick } from '../helpers/lazy-click';
import { watchRelationship } from 'nomad-ui/utils/properties/watch';
import WithVisibilityDetection from 'nomad-ui/mixins/with-component-visibility-detection';
export default Component.extend({
export default Component.extend(WithVisibilityDetection, {
store: service(),
tagName: 'tr',
@@ -27,6 +28,17 @@ export default Component.extend({
}
},
visibilityHandler() {
if (!document.visible) {
this.get('watch').cancelAll();
} else {
const job = this.get('job');
if (job && !job.get('isLoading')) {
this.get('watch').perform(job, 100);
}
}
},
willDestroy() {
this.get('watch').cancelAll();
this._super(...arguments);