Skip to content

Commit

Permalink
Clean up map-layer _registerMediaQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
prushforth committed Dec 18, 2024
1 parent 8e4aa79 commit 7eb1f65
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,9 @@ export class BaseLayerElement extends HTMLElement {
}
_registerMediaQuery(mq) {
if (!this._changeHandler) {
// Define and bind the change handler once
this._changeHandler = () => {
this._onRemove();
if (this._mql.matches) {
// TODO evaluate if _onAdd does the right thing for this situation
this._onAdd();
}
// set the disabled 'read-only' attribute indirectly, via _validateDisabled
Expand All @@ -154,13 +152,11 @@ export class BaseLayerElement extends HTMLElement {
this._mql.removeEventListener('change', this._changeHandler);
}

// Set up the new media query and listener
this._mql = map.matchMedia(mq);
this._changeHandler(); // Initial evaluation
this._changeHandler();
this._mql.addEventListener('change', this._changeHandler);
} else if (this._mql) {
// the media attribute removed or query set to ''
// Clean up the existing listener
this._mql.removeEventListener('change', this._changeHandler);
delete this._mql;
// effectively, no / empty media attribute matches, do what changeHandler does
Expand Down

0 comments on commit 7eb1f65

Please sign in to comment.