Skip to content

Commit 0e64ae6

Browse files
committed
Add getter for initialState to improve typing
1 parent 8afaeec commit 0e64ae6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/controller/ApplicationController.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class ApplicationController<
156156
);
157157

158158
// @ts-ignore
159-
this.state = store(cloneDeep(this.constructor.initialState));
159+
this.state = store(cloneDeep(this.initialState));
160160
if (this.initialize) this.initialize(initialArgs);
161161
this.initialized = true;
162162
} else {
@@ -169,6 +169,17 @@ class ApplicationController<
169169
*/
170170
destroy() {}
171171

172+
/**
173+
* Creates the initial state of the controller.
174+
*/
175+
get initialState(): State {
176+
if ('initialState' in this.constructor) {
177+
return this.constructor.initialState as State;
178+
}
179+
180+
return {} as State;
181+
}
182+
172183
/**
173184
* Internal destroy function. Do not override
174185
* @private

0 commit comments

Comments
 (0)