Skip to content

Commit 2dc2363

Browse files
Muzaffer AydinMuzaffer Aydin
authored andcommitted
fix(wizard) Revert fix wizard bug related changes
1 parent 4ad1655 commit 2dc2363

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

packages/core/src/shared/wizards/wizard.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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()

packages/core/src/test/shared/wizards/wizardTestUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ function failIf(cond: boolean, message?: string): void {
6565
export async function createWizardTester<T extends Partial<T>>(wizard: Wizard<T> | WizardForm<T>): Promise<Tester<T>> {
6666
if (wizard instanceof Wizard && wizard.init) {
6767
// Ensure that init() was called. Needed because createWizardTester() does not call run().
68+
;(wizard as any)._ready = true
6869
await wizard.init()
70+
delete wizard.init
6971
}
7072

7173
const form = wizard instanceof Wizard ? wizard.boundForm : wizard

0 commit comments

Comments
 (0)