Last active
February 2, 2021 05:52
-
-
Save parties/c8623db41f2d9c32abc4a38b61c1863c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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