Skip to content

Instantly share code, notes, and snippets.

@edygar
Last active June 26, 2020 09:42
Show Gist options
  • Save edygar/051b1f60db29914476b43a0e3a902333 to your computer and use it in GitHub Desktop.
Save edygar/051b1f60db29914476b43a0e3a902333 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 fetchMachine = Machine({
id: 'PostingFormPriceEvaluationField',
initial: 'idle',
context: {
featuresValues: {},
missingFeatures: [],
evaluation: null,
},
states: {
idle: {
entry: 'FEATURES_CHANGED',
on: {
FEATURES_CHANGED: {
target: 'pending',
actions: 'setData',
cond: 'checkFilledData'
}
},
},
evaluationUnavailable: {
on: {
FEATURES_CHANGED: {
target: 'pending',
actions: 'setData',
cond: 'checkFilledData'
}
},
},
pending: {
invoke: {
id: 'fetchRangeForFeatures',
src: 'fetchRangeForFeatures',
onDone: {
target: 'fulfilled' ,
actions: 'setRange'
},
onError: 'rejected'
}
},
rejected: {
on: {
FEATURES_CHANGED: {
target: 'pending',
actions: 'setData',
cond: 'checkFilledData'
}
}
},
fulfilled: {
initial: 'missingPrice',
on: {
FEATURES_CHANGED: {
target: 'pending',
actions: 'setData',
cond: 'checkFilledData'
}
},
states: {
missingPrice: {
on: {
'': {
target: 'evaluationShown',
cond: 'hasPrice'
},
'PRICE_SET': {
target: 'evaluationShown',
actions: 'setPrice'
},
}
},
evaluationShown: {},
}
}
}
}, {
services: {
},
actions: {
setPrice() {},
setData() {},
setEvaluation() {},
},
guards: {
checkFilledData() { return true },
hasPrice() { return true }
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment