Skip to content

Commit c6e4651

Browse files
committed
Merge default{State,Config} with constructor options initial{State,Config}
- Previous code is inconsistent with jsdoc description: "Both initial state and initial configuration options are merged with defaults upon initialization." - Generic spread expressions for object literals are supported by TypeScript: microsoft/TypeScript#28234
1 parent 4453cdc commit c6e4651

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/base-controller/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12-
- **BREAKING:** Convert `BaseConfig`, `BaseState` interfaces to types.
12+
- **BREAKING:** The `initialize` method of the `BaseControllerV1` class now merges the `initialState`, `initialConfig` constructor options with `defaultState`, `defaultConfig` before assigning the results to `internalState`, `internalConfig`, instead of simply assigning the defaults ([#3959](https://github.com/MetaMask/core/pull/3959))
13+
- **BREAKING:** Convert `BaseConfig`, `BaseState` interfaces to types ([#3959](https://github.com/MetaMask/core/pull/3959))
1314
- As types, `BaseConfig`, `BaseState` now extend `Record` and have an index signature of `string`.
1415

1516
## [4.1.1]

packages/base-controller/src/BaseControllerV1.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export class BaseControllerV1<C extends BaseConfig, S extends BaseState> {
7171
* @param state - Initial state to set on this controller.
7272
*/
7373
constructor(config: Partial<C> = {}, state: Partial<S> = {}) {
74+
this.initialState = { ...(state as S) };
75+
this.initialConfig = { ...(config as C) };
7476
}
7577

7678
/**
@@ -81,8 +83,8 @@ export class BaseControllerV1<C extends BaseConfig, S extends BaseState> {
8183
* @returns This controller instance.
8284
*/
8385
protected initialize() {
84-
this.internalState = this.defaultState;
85-
this.internalConfig = this.defaultConfig;
86+
this.internalState = { ...this.defaultState, ...this.initialState };
87+
this.internalConfig = { ...this.defaultConfig, ...this.initialConfig };
8688
this.configure(this.initialConfig);
8789
this.update(this.initialState);
8890
return this;

0 commit comments

Comments
 (0)