Replies: 1 comment 3 replies
-
Your wish will be granted (in version 5): #1456 🧞 However, this will be a bit different:
The reason is that there is ambiguity here: // "and" or "or"??
guards: ['guardOne', 'guardTwo'] What does this mean? "guardOne and guardTwo"? Or "guardOne or guardTwo"? You can argue both; some might naturally think that it means "and", but some might think it naturally means "one of these guards" (or). In that PR, there is an even better solution: make it explicit, and allow for guards to be infinitely nested: import { and, or, not } from 'xstate/guards';
// ...
{
guard: and(['guardOne', 'guardTwo'])
}
// ...
{
guard: or(['guardOne', 'guardTwo'])
}
// Have some fun!
{
guard: and(['guardOne', or(['guardTwo', 'guardThree', not('guardFour')])])
} This provides even more explicitness and flexibility versus just assuming that an array means "and" (or "or"). |
Beta Was this translation helpful? Give feedback.
-
I would like to request that the transition property
cond
be renamed toguard
. This will help lessen the cognitive load of learning Xstate for newcomers (can consolidate jargon into one term). And I feel like it just makes sense to call them the same thing since that's howactions
are treated: you specify one or moreactions
in theactions
property.So from
to
I vote for
guard
overcond
becauseBuilding off that recommendation:
To further align Xstate ideas and terminology, I'd like to also suggest we pluralize
guard
toguards
to match even more closely to the mental model ofactions
.guards
should support an array of multiple guards (I believe there to be plenty of use cases for this) just likeactions
does. This helps eliminate needless, nonfunctional memorization of Xstate implementation details. Why would it be different?Thanks for reading and considering!
Beta Was this translation helpful? Give feedback.
All reactions