Skip to content

refactor(grid-list): remove unnecessary regex and cast to array #2502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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