Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Make use of the Array.from mapping function
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMorton committed Sep 16, 2017
1 parent cbc346d commit 9d6ea1e
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/directives/NgGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ export class NgGrid implements OnInit, DoCheck, OnDestroy {
dims = this._resizingItem.getSize();
}

let itemsInGrid: NgGridItem[] = Array.from(this._itemsInGrid).map((itemId: string) => this._items.get(itemId));
let itemsInGrid: NgGridItem[] = Array.from(this._itemsInGrid, (itemId: string) => this._items.get(itemId));

switch (this.cascade) {
case 'up':
Expand Down Expand Up @@ -1150,19 +1150,21 @@ export class NgGrid implements OnInit, DoCheck, OnDestroy {
}

private _getMaxRow(): number {
const itemsRows: number[] = Array.from(this._itemsInGrid)
.map((itemId: string) => this._items.get(itemId))
.filter((item: NgGridItem) => !!item)
.map((item: NgGridItem) => item.row + item.sizey - 1);
const itemsRows: number[] = Array.from(this._itemsInGrid, (itemId: string) => {
const item = this._items.get(itemId);
if (!item) return 0;
return item.row + item.sizey - 1;
});

return Math.max.apply(null, itemsRows);
}

private _getMaxCol(): number {
const itemsCols: number[] = Array.from(this._itemsInGrid)
.map((itemId: string) => this._items.get(itemId))
.filter((item: NgGridItem) => !!item)
.map((item: NgGridItem) => item.col + item.sizex - 1);
const itemsCols: number[] = Array.from(this._itemsInGrid, (itemId: string) => {
const item = this._items.get(itemId);
if (!item) return 0;
return item.col + item.sizex - 1;
});

return Math.max.apply(null, itemsCols);
}
Expand Down Expand Up @@ -1220,21 +1222,15 @@ export class NgGrid implements OnInit, DoCheck, OnDestroy {
}

private _getItemFromPosition(position: NgGridRawPosition): NgGridItem {
const matchedItemId: string = Array.from(this._itemsInGrid).find((itemId: string) => {
const item: NgGridItem = this._items.get(itemId);
if (!item) {
this._itemsInGrid.delete(itemId);
return false;
}
return Array.from(this._itemsInGrid, (itemId: string) => this._items.get(itemId)).find((item: NgGridItem) => {
if (!item) return false;

const size: NgGridItemDimensions = item.getDimensions();
const pos: NgGridRawPosition = item.getPosition();

return position.left > pos.left && position.left < (pos.left + size.width) &&
position.top > pos.top && position.top < (pos.top + size.height);
});

return this._items.get(matchedItemId);
}

private _createPlaceholder(item: NgGridItem): void {
Expand Down

0 comments on commit 9d6ea1e

Please sign in to comment.