Skip to content

Commit

Permalink
fix(esl-media): add exact element resize observation reduce; extra su…
Browse files Browse the repository at this point in the history
…bscriptions manipulation
  • Loading branch information
fshovchko committed May 20, 2024
1 parent 5db802e commit 7e58bbd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/modules/esl-media/core/esl-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import {ExportNs} from '../../esl-utils/environment/export-ns';
import {isElement} from '../../esl-utils/dom/api';
import {CSSClassUtils} from '../../esl-utils/dom/class';
import {SPACE, PAUSE} from '../../esl-utils/dom/keys';
import {prop, attr, boolAttr, listen, decorate} from '../../esl-utils/decorators';
import {debounce, rafDecorator} from '../../esl-utils/async';
import {prop, attr, boolAttr, listen} from '../../esl-utils/decorators';
import {debounce} from '../../esl-utils/async';
import {parseAspectRatio} from '../../esl-utils/misc/format';

import {ESLMediaQuery} from '../../esl-media-query/core';
import {ESLResizeObserverTarget} from '../../esl-event-listener/core';
import {ESLTraversingQuery} from '../../esl-traversing-query/core';

import {getIObserver} from './esl-media-iobserver';
Expand Down Expand Up @@ -190,15 +191,13 @@ export class ESLMedia extends ESLBaseElement {
break;
case 'fill-mode':
case 'aspect-ratio':
this.$$off(this._onResize);
this.$$on(this._onResize);
this._onResize();
break;
case 'play-in-viewport':
this.reattachViewportConstraint();
break;
case 'load-condition':
this.$$off(this._onConditionChange);
this.$$on(this._onConditionChange);
this.deferredReinitialize();
break;
Expand Down Expand Up @@ -327,10 +326,9 @@ export class ESLMedia extends ESLBaseElement {

@listen({
event: 'resize',
target: window,
target: ESLResizeObserverTarget.for,
condition: ($this: ESLMedia) => $this.fillModeEnabled
})
@decorate(rafDecorator)
protected _onResize(): void {
if (!this._provider) return;
if (this.fillModeEnabled && this.actualAspectRatio > 0) {
Expand Down

0 comments on commit 7e58bbd

Please sign in to comment.