Skip to content

Commit 0d9f786

Browse files
committed
refactor: rename all OverlayState references to match the new naming
Renames all of the "state" references in the overlays to refer to a "config" instead. This makes everything consistent with the recent rename of OverlayState to OverlayConfig. BREAKING CHANGE: The `OverlayRef.getState` method has been renamed to `OverlayRef.getConfig`.
1 parent 3571f68 commit 0d9f786

File tree

11 files changed

+92
-92
lines changed

11 files changed

+92
-92
lines changed

src/cdk/overlay/overlay-config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export class OverlayConfig {
5050
/** The direction of the text in the overlay panel. */
5151
direction?: Direction = 'ltr';
5252

53-
constructor(state?: OverlayConfig) {
54-
if (state) {
55-
Object.keys(state).forEach(key => this[key] = state[key]);
53+
constructor(config?: OverlayConfig) {
54+
if (config) {
55+
Object.keys(config).forEach(key => this[key] = config[key]);
5656
}
5757
}
5858
}

src/cdk/overlay/overlay-directives.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('Overlay directives', () => {
7676
let overlayDirective = testComponent.connectedOverlayDirective;
7777

7878
let strategy =
79-
<ConnectedPositionStrategy> overlayDirective.overlayRef.getState().positionStrategy;
79+
<ConnectedPositionStrategy> overlayDirective.overlayRef.getConfig().positionStrategy;
8080
expect(strategy instanceof ConnectedPositionStrategy).toBe(true);
8181

8282
let positions = strategy.positions;

src/cdk/overlay/overlay-directives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export class ConnectedOverlayDirective implements OnDestroy, OnChanges {
337337
}
338338

339339
this._position.withDirection(this.dir);
340-
this._overlayRef.getState().direction = this.dir;
340+
this._overlayRef.getConfig().direction = this.dir;
341341
this._initEscapeListener();
342342

343343
if (!this._overlayRef.hasAttached()) {

src/cdk/overlay/overlay-ref.ts

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ export class OverlayRef implements PortalHost {
2626
constructor(
2727
private _portalHost: PortalHost,
2828
private _pane: HTMLElement,
29-
private _state: OverlayConfig,
29+
private _config: OverlayConfig,
3030
private _ngZone: NgZone) {
3131

32-
if (_state.scrollStrategy) {
33-
_state.scrollStrategy.attach(this);
32+
if (_config.scrollStrategy) {
33+
_config.scrollStrategy.attach(this);
3434
}
3535
}
3636

@@ -47,33 +47,33 @@ export class OverlayRef implements PortalHost {
4747
attach(portal: Portal<any>): any {
4848
let attachResult = this._portalHost.attach(portal);
4949

50-
if (this._state.positionStrategy) {
51-
this._state.positionStrategy.attach(this);
50+
if (this._config.positionStrategy) {
51+
this._config.positionStrategy.attach(this);
5252
}
5353

54-
// Update the pane element with the given state configuration.
54+
// Update the pane element with the given configuration.
5555
this._updateStackingOrder();
5656
this.updateSize();
5757
this.updateDirection();
5858
this.updatePosition();
5959

60-
if (this._state.scrollStrategy) {
61-
this._state.scrollStrategy.enable();
60+
if (this._config.scrollStrategy) {
61+
this._config.scrollStrategy.enable();
6262
}
6363

6464
// Enable pointer events for the overlay pane element.
6565
this._togglePointerEvents(true);
6666

67-
if (this._state.hasBackdrop) {
67+
if (this._config.hasBackdrop) {
6868
this._attachBackdrop();
6969
}
7070

71-
if (this._state.panelClass) {
71+
if (this._config.panelClass) {
7272
// We can't do a spread here, because IE doesn't support setting multiple classes.
73-
if (Array.isArray(this._state.panelClass)) {
74-
this._state.panelClass.forEach(cls => this._pane.classList.add(cls));
73+
if (Array.isArray(this._config.panelClass)) {
74+
this._config.panelClass.forEach(cls => this._pane.classList.add(cls));
7575
} else {
76-
this._pane.classList.add(this._state.panelClass);
76+
this._pane.classList.add(this._config.panelClass);
7777
}
7878
}
7979

@@ -95,8 +95,8 @@ export class OverlayRef implements PortalHost {
9595
// pointer events therefore. Depends on the position strategy and the applied pane boundaries.
9696
this._togglePointerEvents(false);
9797

98-
if (this._state.scrollStrategy) {
99-
this._state.scrollStrategy.disable();
98+
if (this._config.scrollStrategy) {
99+
this._config.scrollStrategy.disable();
100100
}
101101

102102
let detachmentResult = this._portalHost.detach();
@@ -111,12 +111,12 @@ export class OverlayRef implements PortalHost {
111111
* Cleans up the overlay from the DOM.
112112
*/
113113
dispose(): void {
114-
if (this._state.positionStrategy) {
115-
this._state.positionStrategy.dispose();
114+
if (this._config.positionStrategy) {
115+
this._config.positionStrategy.dispose();
116116
}
117117

118-
if (this._state.scrollStrategy) {
119-
this._state.scrollStrategy.disable();
118+
if (this._config.scrollStrategy) {
119+
this._config.scrollStrategy.disable();
120120
}
121121

122122
this.detachBackdrop();
@@ -152,48 +152,48 @@ export class OverlayRef implements PortalHost {
152152
}
153153

154154
/**
155-
* Gets the current state config of the overlay.
155+
* Gets the current config of the overlay.
156156
*/
157-
getState(): OverlayConfig {
158-
return this._state;
157+
getConfig(): OverlayConfig {
158+
return this._config;
159159
}
160160

161161
/** Updates the position of the overlay based on the position strategy. */
162162
updatePosition() {
163-
if (this._state.positionStrategy) {
164-
this._state.positionStrategy.apply();
163+
if (this._config.positionStrategy) {
164+
this._config.positionStrategy.apply();
165165
}
166166
}
167167

168168
/** Updates the text direction of the overlay panel. */
169169
private updateDirection() {
170-
this._pane.setAttribute('dir', this._state.direction!);
170+
this._pane.setAttribute('dir', this._config.direction!);
171171
}
172172

173173
/** Updates the size of the overlay based on the overlay config. */
174174
updateSize() {
175-
if (this._state.width || this._state.width === 0) {
176-
this._pane.style.width = formatCssUnit(this._state.width);
175+
if (this._config.width || this._config.width === 0) {
176+
this._pane.style.width = formatCssUnit(this._config.width);
177177
}
178178

179-
if (this._state.height || this._state.height === 0) {
180-
this._pane.style.height = formatCssUnit(this._state.height);
179+
if (this._config.height || this._config.height === 0) {
180+
this._pane.style.height = formatCssUnit(this._config.height);
181181
}
182182

183-
if (this._state.minWidth || this._state.minWidth === 0) {
184-
this._pane.style.minWidth = formatCssUnit(this._state.minWidth);
183+
if (this._config.minWidth || this._config.minWidth === 0) {
184+
this._pane.style.minWidth = formatCssUnit(this._config.minWidth);
185185
}
186186

187-
if (this._state.minHeight || this._state.minHeight === 0) {
188-
this._pane.style.minHeight = formatCssUnit(this._state.minHeight);
187+
if (this._config.minHeight || this._config.minHeight === 0) {
188+
this._pane.style.minHeight = formatCssUnit(this._config.minHeight);
189189
}
190190

191-
if (this._state.maxWidth || this._state.maxWidth === 0) {
192-
this._pane.style.maxWidth = formatCssUnit(this._state.maxWidth);
191+
if (this._config.maxWidth || this._config.maxWidth === 0) {
192+
this._pane.style.maxWidth = formatCssUnit(this._config.maxWidth);
193193
}
194194

195-
if (this._state.maxHeight || this._state.maxHeight === 0) {
196-
this._pane.style.maxHeight = formatCssUnit(this._state.maxHeight);
195+
if (this._config.maxHeight || this._config.maxHeight === 0) {
196+
this._pane.style.maxHeight = formatCssUnit(this._config.maxHeight);
197197
}
198198
}
199199

@@ -207,8 +207,8 @@ export class OverlayRef implements PortalHost {
207207
this._backdropElement = document.createElement('div');
208208
this._backdropElement.classList.add('cdk-overlay-backdrop');
209209

210-
if (this._state.backdropClass) {
211-
this._backdropElement.classList.add(this._state.backdropClass);
210+
if (this._config.backdropClass) {
211+
this._backdropElement.classList.add(this._config.backdropClass);
212212
}
213213

214214
// Insert the backdrop before the pane in the DOM order,
@@ -261,8 +261,8 @@ export class OverlayRef implements PortalHost {
261261

262262
backdropToDetach.classList.remove('cdk-overlay-backdrop-showing');
263263

264-
if (this._state.backdropClass) {
265-
backdropToDetach.classList.remove(this._state.backdropClass);
264+
if (this._config.backdropClass) {
265+
backdropToDetach.classList.remove(this._config.backdropClass);
266266
}
267267

268268
backdropToDetach.addEventListener('transitionend', finishDetach);

src/cdk/overlay/overlay.spec.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ describe('Overlay', () => {
133133
});
134134

135135
it('should set the direction', () => {
136-
const state = new OverlayConfig({direction: 'rtl'});
136+
const config = new OverlayConfig({direction: 'rtl'});
137137

138-
overlay.create(state).attach(componentPortal);
138+
overlay.create(config).attach(componentPortal);
139139

140140
const pane = overlayContainerElement.children[0] as HTMLElement;
141141
expect(pane.getAttribute('dir')).toEqual('rtl');
@@ -152,8 +152,8 @@ describe('Overlay', () => {
152152
});
153153

154154
it('should emit the attachment event after everything is added to the DOM', () => {
155-
let state = new OverlayConfig({hasBackdrop: true});
156-
let overlayRef = overlay.create(state);
155+
let config = new OverlayConfig({hasBackdrop: true});
156+
let overlayRef = overlay.create(config);
157157

158158
overlayRef.attachments().subscribe(() => {
159159
expect(overlayContainerElement.querySelector('pizza'))
@@ -220,99 +220,99 @@ describe('Overlay', () => {
220220
});
221221

222222
describe('positioning', () => {
223-
let state: OverlayConfig;
223+
let config: OverlayConfig;
224224

225225
beforeEach(() => {
226-
state = new OverlayConfig();
226+
config = new OverlayConfig();
227227
});
228228

229229
it('should apply the positioning strategy', () => {
230-
state.positionStrategy = new FakePositionStrategy();
230+
config.positionStrategy = new FakePositionStrategy();
231231

232-
overlay.create(state).attach(componentPortal);
232+
overlay.create(config).attach(componentPortal);
233233

234234
expect(overlayContainerElement.querySelectorAll('.fake-positioned').length).toBe(1);
235235
});
236236
});
237237

238238
describe('size', () => {
239-
let state: OverlayConfig;
239+
let config: OverlayConfig;
240240

241241
beforeEach(() => {
242-
state = new OverlayConfig();
242+
config = new OverlayConfig();
243243
});
244244

245245
it('should apply the width set in the config', () => {
246-
state.width = 500;
246+
config.width = 500;
247247

248-
overlay.create(state).attach(componentPortal);
248+
overlay.create(config).attach(componentPortal);
249249
const pane = overlayContainerElement.children[0] as HTMLElement;
250250
expect(pane.style.width).toEqual('500px');
251251
});
252252

253253
it('should support using other units if a string width is provided', () => {
254-
state.width = '200%';
254+
config.width = '200%';
255255

256-
overlay.create(state).attach(componentPortal);
256+
overlay.create(config).attach(componentPortal);
257257
const pane = overlayContainerElement.children[0] as HTMLElement;
258258
expect(pane.style.width).toEqual('200%');
259259
});
260260

261261
it('should apply the height set in the config', () => {
262-
state.height = 500;
262+
config.height = 500;
263263

264-
overlay.create(state).attach(componentPortal);
264+
overlay.create(config).attach(componentPortal);
265265
const pane = overlayContainerElement.children[0] as HTMLElement;
266266
expect(pane.style.height).toEqual('500px');
267267
});
268268

269269
it('should support using other units if a string height is provided', () => {
270-
state.height = '100vh';
270+
config.height = '100vh';
271271

272-
overlay.create(state).attach(componentPortal);
272+
overlay.create(config).attach(componentPortal);
273273
const pane = overlayContainerElement.children[0] as HTMLElement;
274274
expect(pane.style.height).toEqual('100vh');
275275
});
276276

277277
it('should apply the min width set in the config', () => {
278-
state.minWidth = 200;
278+
config.minWidth = 200;
279279

280-
overlay.create(state).attach(componentPortal);
280+
overlay.create(config).attach(componentPortal);
281281
const pane = overlayContainerElement.children[0] as HTMLElement;
282282
expect(pane.style.minWidth).toEqual('200px');
283283
});
284284

285285

286286
it('should apply the min height set in the config', () => {
287-
state.minHeight = 500;
287+
config.minHeight = 500;
288288

289-
overlay.create(state).attach(componentPortal);
289+
overlay.create(config).attach(componentPortal);
290290
const pane = overlayContainerElement.children[0] as HTMLElement;
291291
expect(pane.style.minHeight).toEqual('500px');
292292
});
293293

294294
it('should apply the max width set in the config', () => {
295-
state.maxWidth = 200;
295+
config.maxWidth = 200;
296296

297-
overlay.create(state).attach(componentPortal);
297+
overlay.create(config).attach(componentPortal);
298298
const pane = overlayContainerElement.children[0] as HTMLElement;
299299
expect(pane.style.maxWidth).toEqual('200px');
300300
});
301301

302302

303303
it('should apply the max height set in the config', () => {
304-
state.maxHeight = 500;
304+
config.maxHeight = 500;
305305

306-
overlay.create(state).attach(componentPortal);
306+
overlay.create(config).attach(componentPortal);
307307
const pane = overlayContainerElement.children[0] as HTMLElement;
308308
expect(pane.style.maxHeight).toEqual('500px');
309309
});
310310

311311
it('should support zero widths and heights', () => {
312-
state.width = 0;
313-
state.height = 0;
312+
config.width = 0;
313+
config.height = 0;
314314

315-
overlay.create(state).attach(componentPortal);
315+
overlay.create(config).attach(componentPortal);
316316
const pane = overlayContainerElement.children[0] as HTMLElement;
317317
expect(pane.style.width).toEqual('0px');
318318
expect(pane.style.height).toEqual('0px');

src/cdk/overlay/overlay.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import {ScrollStrategyOptions} from './scroll/index';
2424
/** Next overlay unique ID. */
2525
let nextUniqueId = 0;
2626

27-
/** The default state for newly created overlays. */
28-
let defaultState = new OverlayConfig();
27+
/** The default config for newly created overlays. */
28+
let defaultConfig = new OverlayConfig();
2929

3030

3131
/**
@@ -48,13 +48,13 @@ export class Overlay {
4848

4949
/**
5050
* Creates an overlay.
51-
* @param state State to apply to the overlay.
51+
* @param config Config to apply to the overlay.
5252
* @returns Reference to the created overlay.
5353
*/
54-
create(state: OverlayConfig = defaultState): OverlayRef {
54+
create(config: OverlayConfig = defaultConfig): OverlayRef {
5555
const pane = this._createPaneElement();
5656
const portalHost = this._createPortalHost(pane);
57-
return new OverlayRef(portalHost, pane, state, this._ngZone);
57+
return new OverlayRef(portalHost, pane, config, this._ngZone);
5858
}
5959

6060
/**

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
451451
this._overlayRef = this._overlay.create(this._getOverlayConfig());
452452
} else {
453453
/** Update the panel width, in case the host width has changed */
454-
this._overlayRef.getState().width = this._getHostWidth();
454+
this._overlayRef.getConfig().width = this._getHostWidth();
455455
this._overlayRef.updateSize();
456456
}
457457

0 commit comments

Comments
 (0)