All files / src BaseMatchMedia.js

92.85% Statements 13/14
50% Branches 2/4
66.66% Functions 2/3
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32                  2x 2x   2x 2x 2x         2x 2x 2x         1x 1x 1x 1x 1x  
// @ts-check
 
export default class BaseMatchMedia {
  /**
   *
   * @param {string} query
   * @param {(match: boolean)=> any} cb
   */
  constructor(query, cb) {
    this.cb = (/** @type {MediaQueryListEvent} */ mm) => cb(mm.matches);
    Eif (typeof window.matchMedia !== "undefined") {
      /** @type {?MediaQueryList} */
      this.mqList = window.matchMedia(query);
      this.mqList.addListener(this.cb);
      return cb(this.mqList.matches);
    }
  }
 
  close() {
    Eif (this.mqList) {
      this.mqList.removeListener(this.cb);
      this.mqList = null;
    }
  }
}
 
BaseMatchMedia.SM = "(min-width: 576px)";
BaseMatchMedia.MD = "(min-width: 768px)";
BaseMatchMedia.LG = "(min-width: 992px)";
BaseMatchMedia.XL = "(min-width: 1200px)";
BaseMatchMedia.XXL = "(min-width: 1400px)";