Skip to content

Commit

Permalink
refactor(grid-list): remove unnecessary regex and cast to array (angu…
Browse files Browse the repository at this point in the history
…lar#2502)

* Removes a regex that can be replaced by a faster `indexOf` check.
* Removes an unnecessary cast from a QueryList to an Array.
  • Loading branch information
crisbeto authored and kara committed Jan 20, 2017
1 parent f8bd374 commit 64f7c17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/lib/grid-list/grid-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class MdGridList implements OnInit, AfterContentChecked {
private _setTileStyler(): void {
if (this._rowHeight === MD_FIT_MODE) {
this._tileStyler = new FitTileStyler();
} else if (this._rowHeight && this._rowHeight.match(/:/g)) {
} else if (this._rowHeight && this._rowHeight.indexOf(':') > -1) {
this._tileStyler = new RatioTileStyler(this._rowHeight);
} else {
this._tileStyler = new FixedTileStyler(this._rowHeight);
Expand All @@ -122,16 +122,15 @@ export class MdGridList implements OnInit, AfterContentChecked {

/** Computes and applies the size and position for all children grid tiles. */
private _layoutTiles(): void {
let tiles = this._tiles.toArray();
let tracker = new TileCoordinator(this.cols, tiles);
let tracker = new TileCoordinator(this.cols, this._tiles);
let direction = this._dir ? this._dir.value : 'ltr';
this._tileStyler.init(this.gutterSize, tracker, this.cols, direction);

for (let i = 0; i < tiles.length; i++) {
let pos = tracker.positions[i];
let tile = tiles[i];
this._tiles.forEach((tile, index) => {
let pos = tracker.positions[index];
this._tileStyler.setStyle(tile, pos.row, pos.col);
}
});

this._setListStyle(this._tileStyler.getComputedHeight());
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib/grid-list/tile-coordinator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {QueryList} from '@angular/core';
import {MdGridTile} from './grid-tile';
import {MdGridTileTooWideError} from './grid-list-errors';

Expand Down Expand Up @@ -43,7 +44,7 @@ export class TileCoordinator {
/** The computed (row, col) position of each tile (the output). */
positions: TilePosition[];

constructor(numColumns: number, tiles: MdGridTile[]) {
constructor(numColumns: number, tiles: QueryList<MdGridTile>) {
this.tracker = new Array(numColumns);
this.tracker.fill(0, 0, this.tracker.length);

Expand Down

0 comments on commit 64f7c17

Please sign in to comment.