Last active
January 27, 2020 01:29
-
-
Save cellog/d4a3935aee09d09f94153aaeb6cd3e74 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 isRealBounds = ( | |
context, | |
event | |
) => { | |
if (!event.templateId || !context || !context.attributeBoundsTemplates) return false; | |
return ( | |
context.attributeBoundsTemplates[event.templateId].bounds.type === | |
"real_bounds" | |
); | |
}; | |
const isIntegerBounds = ( | |
context, | |
event | |
) => { | |
if (!event.templateId || !context || !context.attributeBoundsTemplates) return false; | |
return ( | |
context.attributeBoundsTemplates[event.templateId].bounds.type === | |
"integer_bounds" | |
); | |
}; | |
const changeObjectContext = { | |
"select Object & State": { | |
target: "#attribute bounds.loadingAttributeBounds", | |
actions: "selectObjectType", | |
}, | |
"select Attribute Type": { | |
target: "#attribute bounds.loadingAttributeBounds", | |
actions: "selectAttributeType", | |
}, | |
}; | |
const filterMachine = Machine({ | |
id: "attribute bounds", | |
initial: "loadingAttributeBounds", | |
context: { | |
selectedObject: "material_spec", | |
selectedAttributeType: "property_template", | |
attributeBoundTemplates: { | |
real: { | |
type: "real_bounds", | |
}, | |
integer: { | |
type: "integer_bounds", | |
} | |
}, | |
formFields: {}, | |
}, | |
states: { | |
loadedBounds: { | |
on: { | |
...changeObjectContext, | |
"select Attribute Name": [ | |
{ | |
target: "searchRealBounds", | |
cond: isRealBounds, | |
}, | |
{ | |
target: "searchIntegerBounds", | |
cond: isIntegerBounds, | |
}, | |
], | |
}, | |
}, | |
searchRealBounds: { | |
on: { | |
...changeObjectContext, | |
"change Lower Bound": { | |
target: "", | |
actions: "changeLowerBound", | |
}, | |
"change Upper Bound": { | |
target: "", | |
actions: "changeUpperBound", | |
}, | |
"change Default Units": { | |
target: "", | |
actions: "changeDefaultUnits", | |
}, | |
search: [ | |
{ | |
target: ".validationErrors", | |
cond: "invalidFormFields", | |
actions: "addValidationErrors", | |
}, | |
{ | |
target: "#attribute bounds.search", | |
}, | |
], | |
}, | |
states: { | |
validationErrors: { | |
on: { | |
...changeObjectContext, | |
"change Lower Bound": { | |
target: "", | |
actions: "changeLowerBound", | |
}, | |
"change Upper Bound": { | |
target: "", | |
actions: "changeUpperBound", | |
}, | |
"change Default Units": { | |
target: "", | |
actions: "changeDefaultUnits", | |
}, | |
search: [ | |
{ | |
target: "", | |
cond: "invalidFormFields", | |
actions: "addValidationErrors", | |
}, | |
{ | |
target: "#attribute bounds.search", | |
}, | |
], | |
}, | |
}, | |
}, | |
}, | |
searchIntegerBounds: { | |
on: { | |
...changeObjectContext, | |
"change Lower Bound": { | |
target: "", | |
actions: "changeLowerBound", | |
}, | |
"change Upper Bound": { | |
target: "", | |
actions: "changeUpperBound", | |
}, | |
search: [ | |
{ | |
target: ".validationErrors", | |
cond: "hasInvalidBounds", | |
actions: "addValidationErrors", | |
}, | |
{ | |
target: "#attribute bounds.search", | |
}, | |
], | |
}, | |
states: { | |
validationErrors: { | |
...changeObjectContext, | |
on: { | |
"change Lower Bound": { | |
target: "", | |
actions: "changeLowerBound", | |
}, | |
"change Upper Bound": { | |
target: "", | |
actions: "changeUpperBound", | |
}, | |
search: [ | |
{ | |
target: "", | |
cond: "hasInvalidBounds", | |
actions: "addValidationErrors", | |
}, | |
{ | |
target: "#attribute bounds.search", | |
}, | |
], | |
}, | |
}, | |
}, | |
}, | |
loadingAttributeBounds: { | |
invoke: { | |
id: "loadBounds", | |
src: "loadAttributeBounds", | |
onDone: { | |
target: "loadedBounds", | |
actions: "saveBoundsObjects", | |
}, | |
onError: { | |
target: "loadingError", | |
actions: "saveLoadingError", | |
}, | |
}, | |
}, | |
loadingError: { | |
on: { | |
...changeObjectContext, | |
}, | |
}, | |
search: { | |
on: { | |
...changeObjectContext, | |
}, | |
}, | |
}, | |
}, { | |
actions: { | |
isRealBounds, | |
isIntegerBounds, | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment