Skip to content

Commit

Permalink
refactor: rename all OverlayState references to match the new naming
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
crisbeto committed Sep 27, 2017
1 parent 3571f68 commit 0d9f786
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 92 deletions.
6 changes: 3 additions & 3 deletions src/cdk/overlay/overlay-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export class OverlayConfig {
/** The direction of the text in the overlay panel. */
direction?: Direction = 'ltr';

constructor(state?: OverlayConfig) {
if (state) {
Object.keys(state).forEach(key => this[key] = state[key]);
constructor(config?: OverlayConfig) {
if (config) {
Object.keys(config).forEach(key => this[key] = config[key]);
}
}
}
2 changes: 1 addition & 1 deletion src/cdk/overlay/overlay-directives.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('Overlay directives', () => {
let overlayDirective = testComponent.connectedOverlayDirective;

let strategy =
<ConnectedPositionStrategy> overlayDirective.overlayRef.getState().positionStrategy;
<ConnectedPositionStrategy> overlayDirective.overlayRef.getConfig().positionStrategy;
expect(strategy instanceof ConnectedPositionStrategy).toBe(true);

let positions = strategy.positions;
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/overlay/overlay-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class ConnectedOverlayDirective implements OnDestroy, OnChanges {
}

this._position.withDirection(this.dir);
this._overlayRef.getState().direction = this.dir;
this._overlayRef.getConfig().direction = this.dir;
this._initEscapeListener();

if (!this._overlayRef.hasAttached()) {
Expand Down
82 changes: 41 additions & 41 deletions src/cdk/overlay/overlay-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export class OverlayRef implements PortalHost {
constructor(
private _portalHost: PortalHost,
private _pane: HTMLElement,
private _state: OverlayConfig,
private _config: OverlayConfig,
private _ngZone: NgZone) {

if (_state.scrollStrategy) {
_state.scrollStrategy.attach(this);
if (_config.scrollStrategy) {
_config.scrollStrategy.attach(this);
}
}

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

if (this._state.positionStrategy) {
this._state.positionStrategy.attach(this);
if (this._config.positionStrategy) {
this._config.positionStrategy.attach(this);
}

// Update the pane element with the given state configuration.
// Update the pane element with the given configuration.
this._updateStackingOrder();
this.updateSize();
this.updateDirection();
this.updatePosition();

if (this._state.scrollStrategy) {
this._state.scrollStrategy.enable();
if (this._config.scrollStrategy) {
this._config.scrollStrategy.enable();
}

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

if (this._state.hasBackdrop) {
if (this._config.hasBackdrop) {
this._attachBackdrop();
}

if (this._state.panelClass) {
if (this._config.panelClass) {
// We can't do a spread here, because IE doesn't support setting multiple classes.
if (Array.isArray(this._state.panelClass)) {
this._state.panelClass.forEach(cls => this._pane.classList.add(cls));
if (Array.isArray(this._config.panelClass)) {
this._config.panelClass.forEach(cls => this._pane.classList.add(cls));
} else {
this._pane.classList.add(this._state.panelClass);
this._pane.classList.add(this._config.panelClass);
}
}

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

if (this._state.scrollStrategy) {
this._state.scrollStrategy.disable();
if (this._config.scrollStrategy) {
this._config.scrollStrategy.disable();
}

let detachmentResult = this._portalHost.detach();
Expand All @@ -111,12 +111,12 @@ export class OverlayRef implements PortalHost {
* Cleans up the overlay from the DOM.
*/
dispose(): void {
if (this._state.positionStrategy) {
this._state.positionStrategy.dispose();
if (this._config.positionStrategy) {
this._config.positionStrategy.dispose();
}

if (this._state.scrollStrategy) {
this._state.scrollStrategy.disable();
if (this._config.scrollStrategy) {
this._config.scrollStrategy.disable();
}

this.detachBackdrop();
Expand Down Expand Up @@ -152,48 +152,48 @@ export class OverlayRef implements PortalHost {
}

/**
* Gets the current state config of the overlay.
* Gets the current config of the overlay.
*/
getState(): OverlayConfig {
return this._state;
getConfig(): OverlayConfig {
return this._config;
}

/** Updates the position of the overlay based on the position strategy. */
updatePosition() {
if (this._state.positionStrategy) {
this._state.positionStrategy.apply();
if (this._config.positionStrategy) {
this._config.positionStrategy.apply();
}
}

/** Updates the text direction of the overlay panel. */
private updateDirection() {
this._pane.setAttribute('dir', this._state.direction!);
this._pane.setAttribute('dir', this._config.direction!);
}

/** Updates the size of the overlay based on the overlay config. */
updateSize() {
if (this._state.width || this._state.width === 0) {
this._pane.style.width = formatCssUnit(this._state.width);
if (this._config.width || this._config.width === 0) {
this._pane.style.width = formatCssUnit(this._config.width);
}

if (this._state.height || this._state.height === 0) {
this._pane.style.height = formatCssUnit(this._state.height);
if (this._config.height || this._config.height === 0) {
this._pane.style.height = formatCssUnit(this._config.height);
}

if (this._state.minWidth || this._state.minWidth === 0) {
this._pane.style.minWidth = formatCssUnit(this._state.minWidth);
if (this._config.minWidth || this._config.minWidth === 0) {
this._pane.style.minWidth = formatCssUnit(this._config.minWidth);
}

if (this._state.minHeight || this._state.minHeight === 0) {
this._pane.style.minHeight = formatCssUnit(this._state.minHeight);
if (this._config.minHeight || this._config.minHeight === 0) {
this._pane.style.minHeight = formatCssUnit(this._config.minHeight);
}

if (this._state.maxWidth || this._state.maxWidth === 0) {
this._pane.style.maxWidth = formatCssUnit(this._state.maxWidth);
if (this._config.maxWidth || this._config.maxWidth === 0) {
this._pane.style.maxWidth = formatCssUnit(this._config.maxWidth);
}

if (this._state.maxHeight || this._state.maxHeight === 0) {
this._pane.style.maxHeight = formatCssUnit(this._state.maxHeight);
if (this._config.maxHeight || this._config.maxHeight === 0) {
this._pane.style.maxHeight = formatCssUnit(this._config.maxHeight);
}
}

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

if (this._state.backdropClass) {
this._backdropElement.classList.add(this._state.backdropClass);
if (this._config.backdropClass) {
this._backdropElement.classList.add(this._config.backdropClass);
}

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

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

if (this._state.backdropClass) {
backdropToDetach.classList.remove(this._state.backdropClass);
if (this._config.backdropClass) {
backdropToDetach.classList.remove(this._config.backdropClass);
}

backdropToDetach.addEventListener('transitionend', finishDetach);
Expand Down
58 changes: 29 additions & 29 deletions src/cdk/overlay/overlay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ describe('Overlay', () => {
});

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

overlay.create(state).attach(componentPortal);
overlay.create(config).attach(componentPortal);

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

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

overlayRef.attachments().subscribe(() => {
expect(overlayContainerElement.querySelector('pizza'))
Expand Down Expand Up @@ -220,99 +220,99 @@ describe('Overlay', () => {
});

describe('positioning', () => {
let state: OverlayConfig;
let config: OverlayConfig;

beforeEach(() => {
state = new OverlayConfig();
config = new OverlayConfig();
});

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

overlay.create(state).attach(componentPortal);
overlay.create(config).attach(componentPortal);

expect(overlayContainerElement.querySelectorAll('.fake-positioned').length).toBe(1);
});
});

describe('size', () => {
let state: OverlayConfig;
let config: OverlayConfig;

beforeEach(() => {
state = new OverlayConfig();
config = new OverlayConfig();
});

it('should apply the width set in the config', () => {
state.width = 500;
config.width = 500;

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

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

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

it('should apply the height set in the config', () => {
state.height = 500;
config.height = 500;

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

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

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

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

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


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

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

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

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


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

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

it('should support zero widths and heights', () => {
state.width = 0;
state.height = 0;
config.width = 0;
config.height = 0;

overlay.create(state).attach(componentPortal);
overlay.create(config).attach(componentPortal);
const pane = overlayContainerElement.children[0] as HTMLElement;
expect(pane.style.width).toEqual('0px');
expect(pane.style.height).toEqual('0px');
Expand Down
10 changes: 5 additions & 5 deletions src/cdk/overlay/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {ScrollStrategyOptions} from './scroll/index';
/** Next overlay unique ID. */
let nextUniqueId = 0;

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


/**
Expand All @@ -48,13 +48,13 @@ export class Overlay {

/**
* Creates an overlay.
* @param state State to apply to the overlay.
* @param config Config to apply to the overlay.
* @returns Reference to the created overlay.
*/
create(state: OverlayConfig = defaultState): OverlayRef {
create(config: OverlayConfig = defaultConfig): OverlayRef {
const pane = this._createPaneElement();
const portalHost = this._createPortalHost(pane);
return new OverlayRef(portalHost, pane, state, this._ngZone);
return new OverlayRef(portalHost, pane, config, this._ngZone);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
this._overlayRef = this._overlay.create(this._getOverlayConfig());
} else {
/** Update the panel width, in case the host width has changed */
this._overlayRef.getState().width = this._getHostWidth();
this._overlayRef.getConfig().width = this._getHostWidth();
this._overlayRef.updateSize();
}

Expand Down
Loading

0 comments on commit 0d9f786

Please sign in to comment.