Returns send from update:
A Common pattern is to update the context then immediately send an event to transition as illustrated by the async example). With this PR, the following two lines:
Allows events to contain arbitrary payload:
Until now there was no simple way to bring outside data into the state machine context (like a form or a subscription). With this PR, events can be sent in an object notation in addition to the string notation: (e.g. send("TOGGLE") or send({ type: "TOGGLE" }). The latter accepts arbitrary keys and values that can be accessed inside effects and guards.
This PR solves two issues:
Returns
send
fromupdate
: A Common pattern is to update the context then immediately send an event to transition as illustrated by the async example). With this PR, the following two lines:Can now be written as:
Allows events to contain arbitrary payload: Until now there was no simple way to bring outside data into the state machine context (like a form or a subscription). With this PR, events can be sent in an object notation in addition to the string notation: (e.g.
send("TOGGLE")
orsend({ type: "TOGGLE" })
. The latter accepts arbitrary keys and values that can be accessed inside effects and guards.By default all additional values are typed as
any
, but the user can provide custom types as a generic:Closes #28, #31 and #35