'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.devicePixelRatioDetector = undefined;

var _events = require('events');

var _events2 = _interopRequireDefault(_events);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

class devicePixelRatioDetector extends _events2.default {
  constructor() {
    super();

    _initialiseProps.call(this);

    const { devicePixelRatio } = window;
    this.matchMediaMin = window.matchMedia(`screen and (min-resolution: ${devicePixelRatio}dppx)`);
    this.matchMediaMax = window.matchMedia(`screen and (max-resolution: ${devicePixelRatio}dppx)`);
    this.matchMediaMin.addListener(this.callback);
    this.matchMediaMax.addListener(this.callback);
  }
}
exports.devicePixelRatioDetector = devicePixelRatioDetector;

var _initialiseProps = function () {
  this.callback = e => {
    this.matchMediaMin.removeListener(this.callback);
    this.matchMediaMax.removeListener(this.callback);
    const { devicePixelRatio } = window;
    this.matchMediaMin = window.matchMedia(`screen and (min-resolution: ${devicePixelRatio}dppx)`);
    this.matchMediaMax = window.matchMedia(`screen and (max-resolution: ${devicePixelRatio}dppx)`);
    this.matchMediaMin.addListener(this.callback);
    this.matchMediaMax.addListener(this.callback);
    this.emit('change', devicePixelRatio);
  };
};