Skip to content

Commit

Permalink
perf: lazily calculate position of each selectable item
Browse files Browse the repository at this point in the history
  • Loading branch information
mattlewis92 authored and d3lm committed Mar 5, 2019
1 parent ec10811 commit 0c9efaa
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions projects/ngx-drag-to-select/src/lib/select-item.directive.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import { isPlatformBrowser } from '@angular/common';

import {
Directive,
DoCheck,
ElementRef,
EventEmitter,
Inject,
Input,
OnInit,
Output,
PLATFORM_ID,
Renderer2
} from '@angular/core';
import { Directive, DoCheck, ElementRef, Inject, Input, PLATFORM_ID, Renderer2 } from '@angular/core';

import { DragToSelectConfig } from './models';
import { CONFIG } from './tokens';
Expand All @@ -24,7 +13,7 @@ import { calculateBoundingClientRect } from './utils';
class: 'dts-select-item'
}
})
export class SelectItemDirective implements OnInit, DoCheck {
export class SelectItemDirective implements DoCheck {
private _boundingClientRect;

selected = false;
Expand All @@ -43,17 +32,14 @@ export class SelectItemDirective implements OnInit, DoCheck {
private renderer: Renderer2
) {}

ngOnInit() {
if (isPlatformBrowser(this.platformId)) {
this.calculateBoundingClientRect();
}
}

ngDoCheck() {
this.applySelectedClass();
}

getBoundingClientRect() {
if (isPlatformBrowser(this.platformId) && !this._boundingClientRect) {
this.calculateBoundingClientRect();
}
return this._boundingClientRect;
}

Expand Down

0 comments on commit 0c9efaa

Please sign in to comment.