Skip to content

Commit dbbe2f2

Browse files
authored
refactor(grid-list): remove circular dependencies (#19953)
Changes some types in order to avoid a circular dependency between the grid list and the tile styler.
1 parent 60ce108 commit dbbe2f2

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

goldens/ts-circular-deps.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,5 @@
3131
[
3232
"src/cdk/testing/private/e2e/actions.ts",
3333
"src/cdk/testing/private/e2e/query.ts"
34-
],
35-
[
36-
"src/material/grid-list/grid-list.ts",
37-
"src/material/grid-list/tile-styler.ts"
3834
]
3935
]

src/material/grid-list/grid-list.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ import {
2020
} from '@angular/core';
2121
import {MatGridTile} from './grid-tile';
2222
import {TileCoordinator} from './tile-coordinator';
23-
import {TileStyler, FitTileStyler, RatioTileStyler, FixedTileStyler} from './tile-styler';
23+
import {
24+
TileStyler,
25+
FitTileStyler,
26+
RatioTileStyler,
27+
FixedTileStyler,
28+
TileStyleTarget,
29+
} from './tile-styler';
2430
import {Directionality} from '@angular/cdk/bidi';
2531
import {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';
2632
import {MAT_GRID_LIST, MatGridListBase} from './grid-list-base';
@@ -50,7 +56,7 @@ const MAT_FIT_MODE = 'fit';
5056
changeDetection: ChangeDetectionStrategy.OnPush,
5157
encapsulation: ViewEncapsulation.None,
5258
})
53-
export class MatGridList implements MatGridListBase, OnInit, AfterContentChecked {
59+
export class MatGridList implements MatGridListBase, OnInit, AfterContentChecked, TileStyleTarget {
5460
/** Number of columns being rendered. */
5561
private _cols: number;
5662

src/material/grid-list/tile-styler.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {MatGridList} from './grid-list';
9+
import {QueryList} from '@angular/core';
1010
import {MatGridTile} from './grid-tile';
1111
import {TileCoordinator} from './tile-coordinator';
1212

@@ -16,6 +16,12 @@ import {TileCoordinator} from './tile-coordinator';
1616
*/
1717
const cssCalcAllowedValue = /^-?\d+((\.\d+)?[A-Za-z%$]?)+$/;
1818

19+
/** Object that can be styled by the `TileStyler`. */
20+
export interface TileStyleTarget {
21+
_setListStyle(style: [string, string | null] | null): void;
22+
_tiles: QueryList<MatGridTile>;
23+
}
24+
1925
/**
2026
* Sets the style properties for an individual tile, given the position calculated by the
2127
* Tile Coordinator.
@@ -152,7 +158,7 @@ export abstract class TileStyler {
152158
* @param list Grid list that the styler was attached to.
153159
* @docs-private
154160
*/
155-
abstract reset(list: MatGridList): void;
161+
abstract reset(list: TileStyleTarget): void;
156162
}
157163

158164

@@ -185,7 +191,7 @@ export class FixedTileStyler extends TileStyler {
185191
];
186192
}
187193

188-
reset(list: MatGridList) {
194+
reset(list: TileStyleTarget) {
189195
list._setListStyle(['height', null]);
190196

191197
if (list._tiles) {
@@ -232,7 +238,7 @@ export class RatioTileStyler extends TileStyler {
232238
];
233239
}
234240

235-
reset(list: MatGridList) {
241+
reset(list: TileStyleTarget) {
236242
list._setListStyle(['paddingBottom', null]);
237243

238244
list._tiles.forEach(tile => {
@@ -274,7 +280,7 @@ export class FitTileStyler extends TileStyler {
274280
tile._setStyle('height', calc(this.getTileSize(baseTileHeight, tile.rowspan)));
275281
}
276282

277-
reset(list: MatGridList) {
283+
reset(list: TileStyleTarget) {
278284
if (list._tiles) {
279285
list._tiles.forEach(tile => {
280286
tile._setStyle('top', null);

tools/public_api_guard/material/grid-list.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export declare class MatGridAvatarCssMatStyler {
33
static ɵfac: i0.ɵɵFactoryDef<MatGridAvatarCssMatStyler, never>;
44
}
55

6-
export declare class MatGridList implements MatGridListBase, OnInit, AfterContentChecked {
6+
export declare class MatGridList implements MatGridListBase, OnInit, AfterContentChecked, TileStyleTarget {
77
_tiles: QueryList<MatGridTile>;
88
get cols(): number;
99
set cols(value: number);

0 commit comments

Comments
 (0)