Skip to content

Commit d349b9e

Browse files
crisbetojelbourn
authored andcommitted
refactor(grid-list): remove unnecessary coercion functions (#12781)
Removes a couple of functions that either duplicate functionality from `cdk/coercion` or are so simple that they can be inlined instead. This change is non-breaking, because the functions were never exported through the public API.
1 parent 6a889f3 commit d349b9e

File tree

4 files changed

+8
-33
lines changed

4 files changed

+8
-33
lines changed

src/lib/grid-list/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ng_module(
1111
deps = [
1212
"//src/lib/core",
1313
"//src/cdk/bidi",
14+
"//src/cdk/coercion",
1415
],
1516
tsconfig = "//src/lib:tsconfig-build.json",
1617
)

src/lib/grid-list/grid-list-measure.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/lib/grid-list/grid-list.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ import {MatGridTile} from './grid-tile';
2222
import {TileCoordinator} from './tile-coordinator';
2323
import {TileStyler, FitTileStyler, RatioTileStyler, FixedTileStyler} from './tile-styler';
2424
import {Directionality} from '@angular/cdk/bidi';
25-
import {
26-
coerceToString,
27-
coerceToNumber,
28-
} from './grid-list-measure';
25+
import {coerceNumberProperty} from '@angular/cdk/coercion';
2926

3027

3128
// TODO(kara): Conditional (responsive) column count / row size.
@@ -72,17 +69,17 @@ export class MatGridList implements OnInit, AfterContentChecked {
7269
/** Amount of columns in the grid list. */
7370
@Input()
7471
get cols(): number { return this._cols; }
75-
set cols(value: number) { this._cols = coerceToNumber(value); }
72+
set cols(value: number) { this._cols = Math.round(coerceNumberProperty(value)); }
7673

7774
/** Size of the grid list's gutter in pixels. */
7875
@Input()
7976
get gutterSize(): string { return this._gutter; }
80-
set gutterSize(value: string) { this._gutter = coerceToString(value); }
77+
set gutterSize(value: string) { this._gutter = `${value || ''}`; }
8178

8279
/** Set internal representation of row height from the user-provided value. */
8380
@Input()
8481
set rowHeight(value: string | number) {
85-
const newValue = coerceToString(value);
82+
const newValue = `${value || ''}`;
8683

8784
if (newValue !== this._rowHeight) {
8885
this._rowHeight = newValue;

src/lib/grid-list/grid-tile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
ChangeDetectionStrategy,
1919
} from '@angular/core';
2020
import {MatLine, MatLineSetter} from '@angular/material/core';
21-
import {coerceToNumber} from './grid-list-measure';
21+
import {coerceNumberProperty} from '@angular/cdk/coercion';
2222

2323
@Component({
2424
moduleId: module.id,
@@ -41,12 +41,12 @@ export class MatGridTile {
4141
/** Amount of rows that the grid tile takes up. */
4242
@Input()
4343
get rowspan(): number { return this._rowspan; }
44-
set rowspan(value: number) { this._rowspan = coerceToNumber(value); }
44+
set rowspan(value: number) { this._rowspan = Math.round(coerceNumberProperty(value)); }
4545

4646
/** Amount of columns that the grid tile takes up. */
4747
@Input()
4848
get colspan(): number { return this._colspan; }
49-
set colspan(value: number) { this._colspan = coerceToNumber(value); }
49+
set colspan(value: number) { this._colspan = Math.round(coerceNumberProperty(value)); }
5050

5151
/**
5252
* Sets the style of the grid-tile element. Needs to be set manually to avoid

0 commit comments

Comments
 (0)