Skip to content

Instantly share code, notes, and snippets.

@parties
Last active February 2, 2021 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parties/c8623db41f2d9c32abc4a38b61c1863c to your computer and use it in GitHub Desktop.
Save parties/c8623db41f2d9c32abc4a38b61c1863c 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)
const cwfMachine = Machine({
id: 'cwf',
initial: 'idle',
context: {
retries: 0,
vessels: {},
selectedVessel: {},
},
states: {
idle: {
id: 'cwf-idle',
on: {
FETCH_VESSELS: 'loadingVessels',
SELECT_VESSEL: {
target: 'loadingVesselSchedule',
action: 'selectVessel'
},
}
},
loadingVessels: {
type: 'compound',
initial: 'loading',
states: {
loading: {
type: 'atomic',
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
failure: {
type: 'atomic',
on: {
RETRY: 'loading',
}
},
success: {
type: 'final',
},
},
onDone: '#cwf-idle',
},
loadingVesselSchedule: {
id: 'loadingVesselSchedule',
type: 'compound',
initial: 'loading',
states: {
loading: {
type: 'atomic',
on: {
RESOLVE: 'success',
REJECT: 'failure',
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: 'loading',
SELECT_VESSEL: {
target: '#loadingVesselSchedule',
action: 'selectVessel'
}
}
},
},
onDone: {
target: '#editingVesselSchedule',
internal: false,
}
},
editingVesselSchedule: {
id: 'editingVesselSchedule',
type: 'compound',
initial: 'editing',
on: {
SAVE_SCHEDULE: '.saving',
SELECT_VESSEL: {
target: '#loadingVesselSchedule',
action: 'selectVessel'
}
},
states: {
editing: {
on: {
SAVE_SCHEDULE: 'saving',
}
},
saving: {
on: {
RESOLVE: 'saved',
REJECT: 'failure',
}
},
failure: {
on: {
RETRY: 'saving',
}},
saved: {
type: 'final',
on: {
SELECT_VESSEL: '#loadingVesselSchedule'
}
}
}
},
}
}, {
actions: {
selectVessel: assign({
selectedVessel: (context, event) => event.target
})
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment