UNPKG

@exadel/esl

Version:

Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components

35 lines (34 loc) 1.06 kB
import { SyntheticEventTarget } from '../../../esl-utils/dom/events/target'; import { ESLMediaChangeEvent } from './media-query-base'; import { NOT_ALL } from './media-query-const'; export class MediaQueryStaticCondition extends SyntheticEventTarget { constructor(name) { super(); this.name = name; this._condition = NOT_ALL; this._onChange = this._onChange.bind(this); } get matches() { return this._condition.matches; } get condition() { return this._condition; } set condition(value) { const matched = this.matches; this._condition.removeEventListener('change', this._onChange); this._condition = value; this._condition.addEventListener('change', this._onChange); if (matched !== this.matches) this._onChange(); } optimize() { return this; } toString() { return `[${this.name} = ${this._condition}]`; } _onChange() { this.dispatchEvent(new ESLMediaChangeEvent(this.matches)); } }