@@ -94,7 +94,7 @@ export class Wizard<TState extends Partial<Record<keyof TState, unknown>>> {
94
94
private assertReady ( ) {
95
95
// Check for `false` explicity so that the base-class constructor can access `this._form`.
96
96
// We want to guard against confusion when implementing a subclass, not this base-class.
97
- if ( this . _ready === false ) {
97
+ if ( this . _ready === false && this . init ) {
98
98
throw Error ( 'run() (or init()) must be called immediately after creating the Wizard' )
99
99
}
100
100
}
@@ -113,7 +113,7 @@ export class Wizard<TState extends Partial<Record<keyof TState, unknown>>> {
113
113
return this . _stepOffset [ 1 ] + this . stateController . totalSteps
114
114
}
115
115
116
- protected get _form ( ) {
116
+ public get _form ( ) {
117
117
this . assertReady ( )
118
118
return this . __form
119
119
}
@@ -136,23 +136,14 @@ export class Wizard<TState extends Partial<Record<keyof TState, unknown>>> {
136
136
this . _estimator = estimator
137
137
}
138
138
139
- public constructor ( protected readonly options : WizardOptions < TState > = { } ) {
139
+ public constructor ( private readonly options : WizardOptions < TState > = { } ) {
140
140
this . stateController = new StateMachineController ( options . initState as TState )
141
141
this . __form = options . initForm ?? new WizardForm ( )
142
142
this . _exitStep =
143
143
options . exitPrompterProvider !== undefined ? this . createExitStep ( options . exitPrompterProvider ) : undefined
144
144
145
145
// Subclass constructor logic should live in `init()`, if it exists.
146
146
this . _ready = ! this . init
147
-
148
- if ( typeof this . init === 'function' ) {
149
- // eslint-disable-next-line @typescript-eslint/unbound-method
150
- const _init = this . init
151
- this . init = ( ) => {
152
- this . _ready = true
153
- return _init . apply ( this )
154
- }
155
- }
156
147
}
157
148
158
149
/**
@@ -175,6 +166,7 @@ export class Wizard<TState extends Partial<Record<keyof TState, unknown>>> {
175
166
if ( ! this . _ready && this . init ) {
176
167
this . _ready = true // Let init() use `this._form`.
177
168
await this . init ( )
169
+ delete this . init
178
170
}
179
171
180
172
this . assignSteps ( )
0 commit comments