Shreyas arya

Generation

generate functionTue, 24 Jan 2023

pick up an appropriate validator from a list and check if transition is allowed

Script const machine = Machine({ id: 'machine', initial: 'A', states: { A: { on: { EVENT: [ { target: 'B', actions: [ 'selectValidator', 'validate' ] }, ] } }, B: { on: { EVENT: 'A' } } } }); const guards = { selectValidator: context => { if (context.transition.event.type === 'EVENT') { context.validator = _someValidator } }, validate: context => { if (context.transition.event.type === 'EVENT') { context.validator.validate(context) } } }

Questions about programming?Chat with your personal AI assistant