Skip to content

Commit

Permalink
Merge default{State,Config} with constructor options `initial{State…
Browse files Browse the repository at this point in the history
…,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
  • Loading branch information
MajorLift committed Feb 22, 2024
1 parent 05567f2 commit d2748d6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/base-controller/src/BaseControllerV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export class BaseControllerV1<C extends BaseConfig, S extends BaseState> {
* @param state - Initial state to set on this controller.
*/
constructor(config: Partial<C> = {}, state: Partial<S> = {}) {
this.initialState = { ...(state as S) };
this.initialConfig = { ...(config as C) };
}

/**
Expand All @@ -81,8 +83,8 @@ export class BaseControllerV1<C extends BaseConfig, S extends BaseState> {
* @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;
Expand Down

0 comments on commit d2748d6

Please sign in to comment.