fix(overlay): make config immutable for existing refs#7376
fix(overlay): make config immutable for existing refs#7376tinayuangao merged 1 commit intoangular:masterfrom
Conversation
3b49387 to
bc03cc6
Compare
|
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 type Readonly<T> = {
readonly [P in keyof T]: T[P];
}; |
bc03cc6 to
3bbbb17
Compare
|
Added an |
|
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> = { |
src/cdk/overlay/overlay-ref.ts
Outdated
| 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.
3bbbb17 to
6b9a3c3
Compare
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.