Skip to content

Instantly share code, notes, and snippets.

@jamstooks
Last active May 24, 2022 21:37
Show Gist options
  • Save jamstooks/b7371c88bf146c39873cb99bdbc582b9 to your computer and use it in GitHub Desktop.
Save jamstooks/b7371c88bf146c39873cb99bdbc582b9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
// How long to hold a target
const RELEASE_TIMEOUT = 3000
// How long to wait to re-arm
const EXIT_TIMEOUT = 1000
const trapMachine = Machine({
id: 'trap',
initial: 'idle',
context: {
retries: 0
},
states: {
idle: {
on: {
ARM: 'armed'
}
},
armed: {
on: {
DETECTED: 'locked',
DISARM: 'idle'
},
},
locked: {
on: {
RELEASE: "armed",
DISARM: "idle"
},
// after timeout,
// should open and wait for
// ? minutes without a target
after: {
[RELEASE_TIMEOUT]: {
target: "exit"
}
}
},
exit: {
// Waiting for the target to leave
after: {
[EXIT_TIMEOUT]: {
target: "armed"
}
},
on: {
// need a way to reset the clock
// maybe an confirmExit state?
DETECTED: 'exit',
DISARM: 'idle'
},
}
}
});
// const textMachine = Machine({
// id: 'text',
// initial: 'triggered',
// context: {
// test: 0
// },
// states: {
// triggered: {
// // sends first text
// on: {
// VERIFY: 'verified',
// }
// },
// verified: {
// }
// }
// })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment