-
Notifications
You must be signed in to change notification settings - Fork 6.8k
refactor(connected-overlay-directive): avoid issues with property initialization #3228
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
@crisbeto This appears to break md-select panel positioning. Can you fix? |
Fixed @kara. I don't know if calling |
b38e051
to
66bd641
Compare
@@ -172,6 +144,20 @@ export class ConnectedOverlayDirective implements OnDestroy { | |||
this._destroyOverlay(); | |||
} | |||
|
|||
ngOnChanges(changes: SimpleChanges) { | |||
if (changes['open']) { | |||
changes['open'].currentValue ? this._attachOverlay() : this._detachOverlay(); |
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.
After you check changes['open']
, shouldn't you be able to just use this.open
?
(same for others)
src/lib/select/select.ts
Outdated
@@ -577,6 +577,7 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr | |||
} | |||
|
|||
this._checkOverlayWithinViewport(maxScroll); | |||
this._changeDetectorRef.detectChanges(); |
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.
Add comment explaining why this detectChanges
call is necessary
this._position.withOffsetX(offsetX); | ||
} | ||
} | ||
@Input() offsetX: number = 0; |
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.
How significant is the code size difference? We use quite a lot of getter/setters.
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.
A getter/setter combination transpiles to this in ES5:
Object.defineProperty(A.prototype, "thing", {
get: function () {
return this._thing;
},
set: function (value) {
this._thing = value;
},
enumerable: true,
configurable: true
});
I think that it can definitely start adding up over an entire project.
65756d7
to
c690eb2
Compare
Addressed the feedback @jelbourn. |
…tialization * Refactors the `ConnectedOverlayDirective` not to depend on the order in which the `open` and `origin` properties are set. * Moves the `open`, `offsetX` and `offsetY` properties from using setters to `ngOnChanges` since the latter tends to output less JS. Fixes angular#3225.
c690eb2
to
b2225e2
Compare
@jelbourn I've rebased this one and removed the changes to the |
this.open ? this._attachOverlay() : this._detachOverlay(); | ||
} | ||
} | ||
|
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.
Can you add a unit test for the case this fixes?
Added a test case for the changes @jelbourn. |
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
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. |
ConnectedOverlayDirective
not to depend on the order in which theopen
andorigin
properties are set.open
,offsetX
andoffsetY
properties from using setters tongOnChanges
since the latter tends to output less JS.Fixes #3225.