Skip to content

Commit

Permalink
refactor(perf): use set to track listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
iobuhov committed Oct 11, 2024
1 parent d81db8b commit de7dcfa
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export type FocusTargetUpdateEvent = { lastPos: PositionString; targetPos: Posit
export type Listener = (event: FocusTargetUpdateEvent) => void;

export class FocusTargetController {
private _listeners: Listener[];
private _listeners: Set<Listener>;
private _focusTarget: PositionString;
private _positionController: PositionController;
private _layout: VirtualGridLayout;

constructor(pos: PositionController, layout: VirtualGridLayout) {
this._listeners = [];
this._listeners = new Set();
this._focusTarget = this._getInitPosition();
this._positionController = pos;
this._layout = layout;
Expand All @@ -25,11 +25,11 @@ export class FocusTargetController {
}

addListener(listener: Listener): void {
this._listeners.push(listener);
this._listeners.add(listener);
}

removeListener(listener: Listener): void {
this._listeners.splice(this._listeners.indexOf(listener), 1);
this._listeners.delete(listener);
}

updateGridLayout(layout: VirtualGridLayout): void {
Expand Down

0 comments on commit de7dcfa

Please sign in to comment.