Reduce number of event listeners.

This commit is contained in:
Dermot Duffy
2023-08-09 21:32:53 -07:00
parent 330f927fdb
commit fe2adb5b89
2 changed files with 10 additions and 18 deletions
-2
View File
@@ -2,8 +2,6 @@
// TODO: Investigate query spam during a grid load // TODO: Investigate query spam during a grid load
// TODO: Is the query reset in card.ts correct for media filter multi-camera queries that are not all cameras? // TODO: Is the query reset in card.ts correct for media filter multi-camera queries that are not all cameras?
// TODO: Do I need column max? // TODO: Do I need column max?
// TODO: Can SELECT_CHILD_EVENTS only be 'click' and it still work on Android?
// TODO: With live autoplay off only white frames appear?
import { import {
CSSResultGroup, CSSResultGroup,
+6 -12
View File
@@ -29,8 +29,6 @@ export interface MediaGridConstructorOptions {
idAttribute?: string; idAttribute?: string;
} }
const SELECT_CHILD_EVENTS = ['click', 'touchend'];
export class MediaGridController { export class MediaGridController {
protected _host: HTMLElement; protected _host: HTMLElement;
@@ -216,27 +214,23 @@ export class MediaGridController {
this._throttledLayout(); this._throttledLayout();
} }
protected _removeChildEventListeners(child: MediaGridChild): void { protected _addChildEventListeners(child: MediaGridChild): void {
for (const event of SELECT_CHILD_EVENTS) { child.addEventListener('click', this._handleSelectGridCellEvent, {
child.removeEventListener(event, this._handleSelectGridCellEvent, {
capture: true, capture: true,
}); });
}
child.removeEventListener( child.addEventListener(
'frigate-card:media:loaded', 'frigate-card:media:loaded',
this._handleMediaLoadedInfoEvent, this._handleMediaLoadedInfoEvent,
); );
} }
protected _addChildEventListeners(child: MediaGridChild): void { protected _removeChildEventListeners(child: MediaGridChild): void {
for (const event of SELECT_CHILD_EVENTS) { child.removeEventListener('click', this._handleSelectGridCellEvent, {
child.addEventListener(event, this._handleSelectGridCellEvent, {
capture: true, capture: true,
}); });
}
child.addEventListener( child.removeEventListener(
'frigate-card:media:loaded', 'frigate-card:media:loaded',
this._handleMediaLoadedInfoEvent, this._handleMediaLoadedInfoEvent,
); );