Uh oh!
There was an error while loading. Please reload this page.
fix(overlay): make config immutable for existing refs - #7376
Conversation
Rather than cloning and ensuring that everything is immutable at runtime, I think that we can get away with making it immutable in TS. We can add a typeReadonly<T>={readonly[PinkeyofT]: T[P];}; |
jelbourn
commented
Sep 27, 2017
Added an |
crisbeto
commented
Sep 27, 2017
Yeah I forgot to mention that there may be some places that depend on being able to update properties dynamically (e.g. I think the overlay directives do it in case the direction changed between attachments). |
| import {Subject} from 'rxjs/Subject'; | ||
| import {OverlayConfig} from './overlay-config'; | ||
| export type ImmutableObject<T> = { |
| return this._state; | ||
| /** Gets the the current overlay configuration, which is immutable. */ | ||
| getConfig(): ImmutableObject<OverlayConfig> { | ||
| // Clone the config so that it cannot be modified outside of this class. |
| /** Sets the LTR/RTL direction for the overlay. */ | ||
| setDirection(dir: Direction) { | ||
| this._config = {...this._config, direction: dir}; |
There was a problem hiding this comment.
Why clone the config here instead of just setting the direction?
There was a problem hiding this comment.
Because the config is immutable
There was a problem hiding this comment.
Shouldn't it be enough to clone it on init and then work off the clone?
There was a problem hiding this comment.
I like having the config as immutable all the time because it reinforces the fact that something extra needs to be done to update it.
This changes makes the OverlayConfig instance in OverlatRef immutable. Calling `getConfig` will now return a clone of the config to make clear that it cannot be modified directly to change the state of the overlay. This also updates the `updateSize` method to accept a partial config to apply to the existing config (and make a new config instance). This *also* tightens up the typings on Portal.attach BREAKING CHANGE: OverlayRef.getConfig returns an immutable version of the config object. BREAKING CHANGE: OverlayRef.updateSize now accepts a OverlaySizeConfig rather than being based on the existing config object.
This changes makes the OverlayConfig instance in OverlatRef immutable. Calling `getConfig` will now return a clone of the config to make clear that it cannot be modified directly to change the state of the overlay. This also updates the `updateSize` method to accept a partial config to apply to the existing config (and make a new config instance). This *also* tightens up the typings on Portal.attach BREAKING CHANGE: OverlayRef.getConfig returns an immutable version of the config object. BREAKING CHANGE: OverlayRef.updateSize now accepts a OverlaySizeConfig rather than being based on the existing config object.
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. |
This changes makes the OverlayConfig instance in OverlatRef immutable.
Calling
getConfigwill now return a clone of the config to make clearthat it cannot be modified directly to change the state of the overlay.
This also updates the
updateSizemethod to accept a partial config toapply to the existing config (and make a new config instance)
BREAKING CHANGE: OverlayRef.getConfig returns a clone of the config
object.
BREAKING CHANGE: OverlayRef.updateSize now accepts a OverlaySizeConfig
rather than being based on the existing config object.