Skip to content

Instantly share code, notes, and snippets.

@samihult
Last active January 1, 2021 00:24
Show Gist options
  • Select an option

  • Save samihult/f006ebf1cf3cab144190b1a750ed17ac to your computer and use it in GitHub Desktop.

Select an option

Save samihult/f006ebf1cf3cab144190b1a750ed17ac to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine({
id: 'field',
context: {
value: '',
output: ''
},
type: 'parallel',
states: {
value: {
initial: 'empty',
states: {
empty: {
on: {
change: {
target: 'not empty',
cond: 'value is not empty'
}
}
},
'not empty': {
on: {
change: {
target: 'empty',
cond: 'value is empty'
}
}
}
}
},
phase: {
initial: 'untouched',
states: {
untouched: {
on: {
change: 'dirty'
}
},
dirty: {
initial: 'debouncing',
states: {
debouncing: {
after: {
5000: 'validating'
}
},
validating: {
on: {
invalid: 'invalid',
valid: 'valid'
}
},
invalid: {},
valid: {}
},
on: {
unfocus: {
target: '.validating',
internal: true
},
change: {
target: '.debouncing',
internal: false
}
}
}
}
}
}
}, {
guards: {
'value is empty': (context, event) =>
context.value === '',
'value is not empty': (context, event) =>
context.value !== ''
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment