-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Conversation
@@ -53,6 +53,12 @@ export class OverlayState { | |||
/** The direction of the text in the overlay panel. */ | |||
direction?: Direction = 'ltr'; | |||
|
|||
constructor(state?: OverlayState) { | |||
if (state) { |
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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,
};
?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/cdk/overlay/overlay.spec.ts
Outdated
|
||
state.hasBackdrop = true; | ||
|
||
let state = new OverlayState({ hasBackdrop: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omit spaces in braces
There was a problem hiding this 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
Adds a rule to enforce that we have consistent spacing inside curly braces and fixes any violations. Relates to angular#6615 (comment).
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.
b50084b
to
e325ca3
Compare
Adds a rule to enforce that we have consistent spacing inside curly braces and fixes any violations. Relates to angular#6615 (comment).
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Allows for a config object to be passed to the
OverlayState
constructor. This makes the longer configurations a bit more convenient to use.