feat(dispatcher): provide custom default state for wizard

This commit is contained in:
teidesu 2021-06-24 01:12:20 +03:00
parent a2ad4128f1
commit 00d9228c1c

View file

@ -37,6 +37,12 @@ export class WizardScene<State, SceneName extends string = string> extends Dispa
> {
private _steps = 0
private _defaultState: State & WizardInternalState = {} as any
setDefaultState (defaultState: State): void {
this._defaultState = defaultState as State & WizardInternalState
}
/**
* Get the total number of registered steps
*/
@ -60,7 +66,7 @@ export class WizardScene<State, SceneName extends string = string> extends Dispa
const result = await handler(msg, state)
if (typeof result === 'number') {
await state.merge({ $step: result })
await state.merge({ $step: result }, this._defaultState)
return
}
@ -70,7 +76,7 @@ export class WizardScene<State, SceneName extends string = string> extends Dispa
if (next === this._steps) {
await state.exit()
} else {
await state.merge({ $step: next })
await state.merge({ $step: next }, this._defaultState)
}
break
}