Created
April 20, 2021 17:13
-
-
Save avanslaars/59e91b7307a0093ceab9be52dadf1986 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 jllSettingMachine = Machine({ | |
id: 'JllSetting', | |
initial: 'unchanged', | |
context: { | |
original: { | |
threshold: 10, | |
duration: 0, | |
occurance: 0 | |
}, | |
threshold: 10, | |
duration: 0, | |
occurance: 0 | |
}, | |
states: { | |
unchanged: { | |
on: { | |
THRESHOLD_CHANGE: { | |
target: 'changed', | |
cond: 'newThresholdValue', | |
actions: ['updateThreshold'] | |
}, | |
DURATION_CHANGE: { | |
target: 'changed', | |
cond: 'newDurationValue', | |
actions: ['updateDuration'] | |
}, | |
OCCURANCE_CHANGE: { | |
target: 'changed', | |
cond: 'newOccuranceValue', | |
actions: ['updateOccurance'] | |
} | |
} | |
}, | |
changed: { | |
on: { | |
THRESHOLD_CHANGE: [{ | |
target: 'unchanged', | |
cond: 'resetByThreshold', | |
actions: ['updateThreshold'] | |
}, { | |
target: 'changed', | |
actions: ['updateThreshold'] | |
}], | |
DURATION_CHANGE: [{ | |
target: 'unchanged', | |
cond: 'resetByDuration', | |
actions: ['updateDuration'] | |
}, { | |
target: 'changed', | |
actions: ['updateDuration'] | |
}], | |
OCCURANCE_CHANGE: [{ | |
target: 'unchanged', | |
cond: 'resetByOccurance', | |
actions: ['updateOccurance'] | |
}, { | |
target: 'changed', | |
actions: ['updateOccurance'] | |
}] | |
} | |
}, | |
} | |
},{ | |
actions: { | |
updateThreshold: assign({ | |
threshold: (context, event) => event.value | |
}), | |
updateDuration: assign({ | |
duration: (context, event) => event.value | |
}), | |
updateOccurance: assign({ | |
occurance: (context, event) => event.value | |
}) | |
}, | |
guards: { | |
newThresholdValue: (ctx, evt) => ctx.original.threshold !== evt.value, | |
newDurationValue: (ctx, evt) => ctx.original.duration !== evt.value, | |
newOccuranceValue: (ctx, evt) => ctx.original.occurance !== evt.value, | |
resetByThreshold: (ctx, evt) => ctx.original.threshold === evt.value && ctx.original.duration === ctx.duration && ctx.original.occurance === ctx.occurance, | |
resetByDuration: (ctx, evt) => ctx.original.duration === evt.value && ctx.original.threshold === ctx.threshold && ctx.original.occurance === ctx.occurance, | |
resetByOccurance: (ctx, evt) => ctx.original.occurance === evt.value && ctx.original.threshold === ctx.threshold && ctx.original.duration === ctx.duration | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment