Last active
March 29, 2021 12:00
-
-
Save bokuo-okubo/ded95dd75f5bc1aa3e738d820c09bd01 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 fetchMachine = Machine({ | |
id: 'training', | |
initial: 'step1', | |
states: { | |
step1: { | |
type: 'parallel', | |
on: { | |
TRANSISION: { | |
target: 'step2', | |
cond: (ctx, ev, cond) => { | |
const trainingCompleted = cond.state.value.step1.training === 'completed' | |
const evaluationCompletedOrIdle = cond.state.value.step1.evaluation === 'completed' || cond.state.value.step1.evaluation === 'idle' | |
return true | |
} | |
} | |
}, | |
states: { | |
training: { | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
START: 'uploading' | |
} | |
}, | |
uploading: { | |
on: { | |
PROGRESS: { | |
target: 'uploading' | |
}, | |
RESOLVE: 'success', | |
REJECT: 'failure' | |
} | |
}, | |
success: { | |
on: { | |
GO: 'completed' | |
} | |
}, | |
completed: { | |
type: 'final' | |
}, | |
failure: { | |
on: { | |
RETRY: { | |
target: 'uploading' | |
} | |
} | |
} | |
} | |
}, | |
evaluation: { | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
START: 'uploading' | |
} | |
}, | |
uploading: { | |
on: { | |
PROGRESS: { | |
target: 'uploading' | |
}, | |
RESOLVE: 'success', | |
REJECT: 'failure' | |
} | |
}, | |
success: { | |
on: { | |
GO: 'completed' | |
} | |
}, | |
completed: { | |
type: 'final' | |
}, | |
failure: { | |
on: { | |
RETRY: { | |
target: 'uploading' | |
} | |
} | |
} | |
} | |
} | |
} | |
}, // step1 | |
// ------- | |
step2: { | |
initial: 'created', | |
type: 'compound', | |
states: { | |
created: { | |
on: { | |
START: 'progressing.started' | |
} | |
}, | |
progressing: { | |
initial: 'started', | |
states: { | |
started: { | |
on: { | |
RESOLVE: 'validation_done', | |
REJECT: '#training.step2.failure.validation_failure' | |
} | |
}, | |
validation_done: { | |
on: { | |
RESOLVE: 'load_done', | |
REJECT: '#training.step2.failure.unexpected_failure' | |
} | |
}, | |
load_done: { | |
on: { | |
RESOLVE: 'training_done', | |
REJECT: [ | |
{ | |
target: '#training.step2.failure.training_failure', | |
cond: (ctx, ev) => ev.expected | |
}, | |
{ | |
target: '#training.step2.failure.unexpected_failure', | |
cond: (ctx, ev) => !ev.expected | |
} | |
] | |
} | |
}, | |
training_done: { | |
type: 'final' | |
} | |
}, | |
onDone: 'success' | |
},//progressing | |
success: { | |
type: 'final' | |
}, | |
failure: { | |
states: { | |
validation_failure: {}, | |
training_failure: {}, | |
unexpected_failure: {} | |
} | |
} | |
} | |
}, // step2 | |
},//states | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment