Preserve default context on start from named state #573
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When an initial state is not passed to
service.start()
,machine.initialState
is used, which is filled in with a lot of details, particularly a copy of the defaultmachine.context
.When an initial state is passed as a
State
object, it is loaded directly, and it is assumed that this comes with the desired.context
value filled in.But when an initial state is passed as a named state, like
interpret(machine).start("COMMENT_FORM")
, the resulting state has.context === undefined
because nothing ever sets it.State.from()
, which handles loading a string state to a full state object, already had an option to attach a context, but it was not used in this case.Found during #432