Skip to content

Commit aee51c9

Browse files
committed
refactor(overlay): avoid circular type references
Currently there is a circular type reference between `OverlayRef`, `PositionStrategy`/`ScrollStrategy` and `OverlayConfig` which can cause issues with some build tools. These changes introduce the `OverlayRefBase` type to avoid the circular reference. Fixes #9491.
1 parent 0799bee commit aee51c9

File tree

7 files changed

+41
-18
lines changed

7 files changed

+41
-18
lines changed

src/cdk/overlay/overlay-ref-base.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Portal} from '@angular/cdk/portal';
10+
11+
/**
12+
* Basic interface for an overlay. Used to avoid circular type references between
13+
* `OverlayRef`, `PositionStrategy` and `ScrollStrategy`, and `OverlayConfig`.
14+
* @docs-private
15+
*/
16+
export interface OverlayRefBase {
17+
attach: (portal: Portal<any>) => any;
18+
detach: () => any;
19+
dispose: () => void;
20+
overlayElement: HTMLElement;
21+
getConfig: () => any;
22+
hasAttached: () => boolean;
23+
updateSize: (config: any) => void;
24+
updatePosition: () => void;
25+
}

src/cdk/overlay/position/connected-position-strategy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {Subscription} from 'rxjs/Subscription';
2323
import {Observable} from 'rxjs/Observable';
2424
import {CdkScrollable} from '@angular/cdk/scrolling';
2525
import {isElementScrolledOutsideView, isElementClippedByScrolling} from './scroll-clip';
26-
import {OverlayRef} from '../overlay-ref';
26+
import {OverlayRefBase} from '../overlay-ref-base';
2727

2828

2929

@@ -36,7 +36,7 @@ import {OverlayRef} from '../overlay-ref';
3636
*/
3737
export class ConnectedPositionStrategy implements PositionStrategy {
3838
/** The overlay to which this strategy is attached. */
39-
private _overlayRef: OverlayRef;
39+
private _overlayRef: OverlayRefBase;
4040

4141
/** Layout direction of the position strategy. */
4242
private _dir = 'ltr';
@@ -99,7 +99,7 @@ export class ConnectedPositionStrategy implements PositionStrategy {
9999
}
100100

101101
/** Attach this position strategy to an overlay. */
102-
attach(overlayRef: OverlayRef): void {
102+
attach(overlayRef: OverlayRefBase): void {
103103
this._overlayRef = overlayRef;
104104
this._pane = overlayRef.overlayElement;
105105
this._resizeSubscription.unsubscribe();

src/cdk/overlay/position/global-position-strategy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {PositionStrategy} from './position-strategy';
10-
import {OverlayRef} from '../overlay-ref';
10+
import {OverlayRefBase} from '../overlay-ref-base';
1111

1212

1313
/**
@@ -18,7 +18,7 @@ import {OverlayRef} from '../overlay-ref';
1818
*/
1919
export class GlobalPositionStrategy implements PositionStrategy {
2020
/** The overlay to which this strategy is attached. */
21-
private _overlayRef: OverlayRef;
21+
private _overlayRef: OverlayRefBase;
2222

2323
private _cssPosition = 'static';
2424
private _topOffset = '';
@@ -35,7 +35,7 @@ export class GlobalPositionStrategy implements PositionStrategy {
3535

3636
constructor(private _document: any) {}
3737

38-
attach(overlayRef: OverlayRef): void {
38+
attach(overlayRef: OverlayRefBase): void {
3939
const config = overlayRef.getConfig();
4040

4141
this._overlayRef = overlayRef;

src/cdk/overlay/position/position-strategy.ts

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

9-
import {OverlayRef} from '../overlay-ref';
10-
9+
import {OverlayRefBase} from '../overlay-ref-base';
1110

1211
/** Strategy for setting the position on an overlay. */
1312
export interface PositionStrategy {
14-
1513
/** Attaches this position strategy to an overlay. */
16-
attach(overlay: OverlayRef): void;
14+
attach(overlayRef: OverlayRefBase): void;
1715

1816
/** Updates the position of the overlay element. */
1917
apply(): void;

src/cdk/overlay/scroll/close-scroll-strategy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import {NgZone} from '@angular/core';
99
import {ScrollStrategy, getMatScrollStrategyAlreadyAttachedError} from './scroll-strategy';
10-
import {OverlayRef} from '../overlay-ref';
10+
import {OverlayRefBase} from '../overlay-ref-base';
1111
import {Subscription} from 'rxjs/Subscription';
1212
import {ScrollDispatcher, ViewportRuler} from '@angular/cdk/scrolling';
1313

@@ -24,7 +24,7 @@ export interface CloseScrollStrategyConfig {
2424
*/
2525
export class CloseScrollStrategy implements ScrollStrategy {
2626
private _scrollSubscription: Subscription|null = null;
27-
private _overlayRef: OverlayRef;
27+
private _overlayRef: OverlayRefBase;
2828
private _initialScrollPosition: number;
2929

3030
constructor(
@@ -34,7 +34,7 @@ export class CloseScrollStrategy implements ScrollStrategy {
3434
private _config?: CloseScrollStrategyConfig) {}
3535

3636
/** Attaches this scroll strategy to an overlay. */
37-
attach(overlayRef: OverlayRef) {
37+
attach(overlayRef: OverlayRefBase) {
3838
if (this._overlayRef) {
3939
throw getMatScrollStrategyAlreadyAttachedError();
4040
}

src/cdk/overlay/scroll/reposition-scroll-strategy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {NgZone} from '@angular/core';
1010
import {Subscription} from 'rxjs/Subscription';
1111
import {ScrollStrategy, getMatScrollStrategyAlreadyAttachedError} from './scroll-strategy';
12-
import {OverlayRef} from '../overlay-ref';
12+
import {OverlayRefBase} from '../overlay-ref-base';
1313
import {ScrollDispatcher, ViewportRuler} from '@angular/cdk/scrolling';
1414
import {isElementScrolledOutsideView} from '../position/scroll-clip';
1515

@@ -29,7 +29,7 @@ export interface RepositionScrollStrategyConfig {
2929
*/
3030
export class RepositionScrollStrategy implements ScrollStrategy {
3131
private _scrollSubscription: Subscription|null = null;
32-
private _overlayRef: OverlayRef;
32+
private _overlayRef: OverlayRefBase;
3333

3434
constructor(
3535
private _scrollDispatcher: ScrollDispatcher,
@@ -38,7 +38,7 @@ export class RepositionScrollStrategy implements ScrollStrategy {
3838
private _config?: RepositionScrollStrategyConfig) { }
3939

4040
/** Attaches this scroll strategy to an overlay. */
41-
attach(overlayRef: OverlayRef) {
41+
attach(overlayRef: OverlayRefBase) {
4242
if (this._overlayRef) {
4343
throw getMatScrollStrategyAlreadyAttachedError();
4444
}

src/cdk/overlay/scroll/scroll-strategy.ts

Lines changed: 2 additions & 2 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 {OverlayRef} from '../overlay-ref';
9+
import {OverlayRefBase} from '../overlay-ref-base';
1010

1111
/**
1212
* Describes a strategy that will be used by an overlay to handle scroll events while it is open.
@@ -19,7 +19,7 @@ export interface ScrollStrategy {
1919
disable: () => void;
2020

2121
/** Attaches this `ScrollStrategy` to an overlay. */
22-
attach: (overlayRef: OverlayRef) => void;
22+
attach: (overlayRef: OverlayRefBase) => void;
2323
}
2424

2525
/**

0 commit comments

Comments
 (0)