@@ -94,7 +94,7 @@ export class Wizard<TState extends Partial<Record<keyof TState, unknown>>> {
9494 private assertReady ( ) {
9595 // Check for `false` explicity so that the base-class constructor can access `this._form`.
9696 // 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 ) {
9898 throw Error ( 'run() (or init()) must be called immediately after creating the Wizard' )
9999 }
100100 }
@@ -113,7 +113,7 @@ export class Wizard<TState extends Partial<Record<keyof TState, unknown>>> {
113113 return this . _stepOffset [ 1 ] + this . stateController . totalSteps
114114 }
115115
116- protected get _form ( ) {
116+ public get _form ( ) {
117117 this . assertReady ( )
118118 return this . __form
119119 }
@@ -136,23 +136,14 @@ export class Wizard<TState extends Partial<Record<keyof TState, unknown>>> {
136136 this . _estimator = estimator
137137 }
138138
139- public constructor ( protected readonly options : WizardOptions < TState > = { } ) {
139+ public constructor ( private readonly options : WizardOptions < TState > = { } ) {
140140 this . stateController = new StateMachineController ( options . initState as TState )
141141 this . __form = options . initForm ?? new WizardForm ( )
142142 this . _exitStep =
143143 options . exitPrompterProvider !== undefined ? this . createExitStep ( options . exitPrompterProvider ) : undefined
144144
145145 // Subclass constructor logic should live in `init()`, if it exists.
146146 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- }
156147 }
157148
158149 /**
@@ -175,6 +166,7 @@ export class Wizard<TState extends Partial<Record<keyof TState, unknown>>> {
175166 if ( ! this . _ready && this . init ) {
176167 this . _ready = true // Let init() use `this._form`.
177168 await this . init ( )
169+ delete this . init
178170 }
179171
180172 this . assignSteps ( )
0 commit comments