Skip to content

Instantly share code, notes, and snippets.

View tireymorris's full-sized avatar

Tirey Morris tireymorris

  • Austin, TX
  • 08:41 (UTC -05:00)
View GitHub Profile
@tireymorris
tireymorris / useStateMachine.js
Last active October 29, 2025 20:47
`useStateMachine` vue hook
import { ref } from "vue";
export default function useStateMachine(states, initialState = states[0]) {
const state = ref(initialState);
const isTransitioning = ref(false);
const transition = async (targetState, action, errorState = "ERROR") => {
if (!states.includes(targetState)) {
throw new Error(`Invalid state: ${targetState}. Valid states: ${states.join(", ")}`);
}