mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 01:45:44 +03:00
Toggle polling in components when switching away from the tab
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user