open-nomad/ui/app/mixins/with-component-visibility-detection.js
Michael Lange 536c013928 Disable visibility behaviors when testing
It results in surprise behaviors.
2018-05-25 10:15:24 -07:00

23 lines
690 B
JavaScript

import Ember from 'ember';
import Mixin from '@ember/object/mixin';
import { assert } from '@ember/debug';
export default Mixin.create({
visibilityHandler() {
assert('visibilityHandler needs to be overridden in the Component', false);
},
setupDocumentVisibility: function() {
if (!Ember.testing) {
this.set('_visibilityHandler', this.get('visibilityHandler').bind(this));
document.addEventListener('visibilitychange', this.get('_visibilityHandler'));
}
}.on('init'),
removeDocumentVisibility: function() {
if (!Ember.testing) {
document.removeEventListener('visibilitychange', this.get('_visibilityHandler'));
}
}.on('willDestroy'),
});