Xstate: Misleading docs for the guardMeta argument

Created on 19 Apr 2020  路  2Comments  路  Source: davidkpiano/xstate

Description

In the Guards documentation section, the 3rd argument has misleading descriptions:

https://xstate.js.org/docs/guides/guards.html#guards-condition-functions

The condMeta object includes the following properties:

  • cond - the original condition object
  • state - the resolved machine state, after transition
  • _event - the SCXML event

https://xstate.js.org/docs/guides/guards.html#serializing-guards

guardMeta - an object containing meta data about the guard and transition, including:

  • cond - the original cond object
  • state - the current machine state, before transition

Is the state property the machine state after or before transition?
Or is this the different between nonserialized and serialized guard functions?

Whichever the answer is I believe the documentation should clarify.

bug

All 2 comments

Nice catch. I believe the docs are wrong here.
I think a stateGuard always has the current machine state. Only when the guard evaluates to true, the transition can be taken. Therefore, the state in a guard should always be the one before the transition.

Would gladly accept a PR for this one!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jfun picture jfun  路  3Comments

laurentpierson picture laurentpierson  路  3Comments

greggman picture greggman  路  3Comments

mattiamanzati picture mattiamanzati  路  3Comments

suku-h picture suku-h  路  3Comments