#Guard Parameters?
1 messages · Page 1 of 1 (latest)
Guard Parameters?
It works in v4. Haven't seen how it'll work in v5.
The guard:
fieldHasValue: (ctx, event, { cond }) => {
// @ts-expect-error Field does exist
const field = cond.field;
// @ts-expect-error Field does exist
const expectedValue = cond.expected;
return ctx[`${field}`] === expectedValue;
},
And usage:
{
cond: {
type: 'fieldHasValue',
field: 'securityMethod',
expected: 'new-account',
},
target: 'newAccount',
},
How would a user add them on stately ui?
In v5 this works:
Guard:
fieldHasValue: ({context, guard}) => {
const {field, expected} = guard.params;
return context[field] === expected;
}
Usage:
{
target: 'newAccount',
guard: {
type: 'fieldHasValue',
params: {
field: 'securityMethod',
expected: 'new-account',
},
},
},
What about defining it through the stately UI though?
What about defining it through the stately UI though?
Not sure. I haven't tried this use case there.
Guard parameters are in XState v4 and v5:
// XState v4
cond: { type: 'greaterThan', value: 4 }
// XState v5
guard: { type: 'greaterThan', params: { value: 4 } }
// note how params are necessary