We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I'm working on a module that allows rules to be serialized as JSON. It would be nice to do something like this so that I can use it to evaluate the conditions:
const myMachine = Machine( { context: { foo: { bar: ['baz'] } }, initial: 'a', states: { a: { on: { FOO: { target: 'b', // only transition to 'b' if ctx.foo.bar[0] === 'baz' cond: ["==", "$.foo.bar.0", "baz"] } } }, b: {} } }, { evaluateGuard: (cond, ctx, eventObject, interimState) => { // cond: ["==", "$.foo.bar.0", "baz"] return jr.evaluate(cond, ctx); } } ); myMachine.transition('a', 'FOO').value; // b myMachine.transition('a', 'FOO', {foo:{bar:['bag']}}).value; // a
Is this something that would be considered? Thanks
The text was updated successfully, but these errors were encountered:
For sure - the lowest-common denominator is using a string-as-condition and mapping it to a real transition.
Some more discussion about this in #57, but I think that it would be reasonable to allow any JSON-serializable value, not just strings, in cond: ....
cond: ...
Sorry, something went wrong.
Added in 4.4: https://xstate.js.org/docs/guides/guards.html#custom-guards
No branches or pull requests
(Feature) Potential implementation:
I'm working on a module that allows rules to be serialized as JSON. It would be nice to do something like this so that I can use it to evaluate the conditions:
Is this something that would be considered? Thanks
The text was updated successfully, but these errors were encountered: