Skip to content

refactor(overlay): allow for object to be passed to the OverlayState constructor #6615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 1, 2017

Conversation

crisbeto
Copy link
Member

Allows for a config object to be passed to the OverlayState constructor. This makes the longer configurations a bit more convenient to use.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 23, 2017
@@ -53,6 +53,12 @@ export class OverlayState {
/** The direction of the text in the overlay panel. */
direction?: Direction = 'ltr';

constructor(state?: OverlayState) {
if (state) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do this?

extendObject(this, state);

(from core/util, handles null / undefined)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't use extendObject, because it would introduce a dependency between Material and the CDK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I forgot that was in material.

@@ -272,7 +272,12 @@ export class ConnectedOverlayDirective implements OnDestroy, OnChanges {

/** Builds the overlay config based on the directive's inputs */
private _buildConfig(): OverlayState {
let overlayConfig = new OverlayState();
const positionStrategy = this._position = this._createPositionStrategy();
const overlayConfig = new OverlayState({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all of the options are optional now, could you just change most places to, e.g.,

const overlayConfig = {
  positionStrategy,
  scrollStrategy: this.scrollStrategy,
  hasBackdrop: this.hasBackdrop,
};

?

Copy link
Member Author

@crisbeto crisbeto Aug 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I did. The position in this particular case is different, because we want to save a reference to it before we pass it to the OverlayRef.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant omitting the new OverlayState( part and just having the object literal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, gotcha. Instantiating the class lets us apply the default options for things like the direction, backdrop class and scroll strategy.


state.hasBackdrop = true;

let state = new OverlayState({ hasBackdrop: true });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omit spaces in braces

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from the spacing thing

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Aug 24, 2017
crisbeto added a commit to crisbeto/material2 that referenced this pull request Aug 24, 2017
Adds a rule to enforce that we have consistent spacing inside curly braces and fixes any violations.

Relates to angular#6615 (comment).
crisbeto added a commit to crisbeto/material2 that referenced this pull request Aug 24, 2017
Adds a rule to enforce that we have consistent spacing inside curly braces and fixes any violations.

Relates to angular#6615 (comment).
…constructor

Allows for a config object to be passed to the `OverlayState` constructor. This makes the longer configurations a bit more convenient to use.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Aug 29, 2017
Adds a rule to enforce that we have consistent spacing inside curly braces and fixes any violations.

Relates to angular#6615 (comment).
@jelbourn jelbourn merged commit fe37cb2 into angular:master Sep 1, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants