From d2748d66f36b5818e98f8da2be89571963677da1 Mon Sep 17 00:00:00 2001 From: Jongsun Suh Date: Thu, 22 Feb 2024 13:25:47 -0500 Subject: [PATCH] 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: https://github.com/microsoft/TypeScript/pull/28234 --- packages/base-controller/src/BaseControllerV1.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/base-controller/src/BaseControllerV1.ts b/packages/base-controller/src/BaseControllerV1.ts index 65d79030c97..c5d0f89896f 100644 --- a/packages/base-controller/src/BaseControllerV1.ts +++ b/packages/base-controller/src/BaseControllerV1.ts @@ -71,6 +71,8 @@ export class BaseControllerV1 { * @param state - Initial state to set on this controller. */ constructor(config: Partial = {}, state: Partial = {}) { + this.initialState = { ...(state as S) }; + this.initialConfig = { ...(config as C) }; } /** @@ -81,8 +83,8 @@ export class BaseControllerV1 { * @returns This controller instance. */ protected initialize() { - this.internalState = this.defaultState; - this.internalConfig = this.defaultConfig; + this.internalState = { ...this.defaultState, ...this.internalState }; + this.internalConfig = { ...this.defaultConfig, ...this.internalConfig }; this.configure(this.initialConfig); this.update(this.initialState); return this;