Last active
May 11, 2021 15:34
-
-
Save avanslaars/2bbd050d473357b68bf081fafc40ecdb 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 metricSetting = Machine({ | |
id: 'metricSetting', | |
initial: 'unpopulated', | |
context: { | |
original: { | |
threshold: 0, | |
duration: 0, | |
occurrence: 0, | |
notifications: [] | |
}, | |
threshold: 0, | |
duration: 0, | |
occurrence: 0, | |
notifications: [] | |
}, | |
states: { | |
unpopulated: { | |
on: { | |
ACTIVATE: 'populated' | |
} | |
}, | |
populated: { | |
type: 'parallel', | |
on: { | |
REMOVE: { | |
target: 'unpopulated', | |
actions: ['clearMetric'] | |
} | |
}, | |
states: { | |
status: { | |
initial: 'init', | |
states: { | |
init: { | |
on: { | |
"": [ | |
{target: 'modified', cond: 'isChanged'}, | |
{ | |
target: 'unmodified' | |
} | |
] | |
} | |
}, | |
unmodified: {}, | |
modified: {} | |
} | |
}, | |
mode: { | |
initial: 'read', | |
on: { | |
EDIT_THRESHOLD: { target: '.edit.threshold' }, | |
EDIT_TIMINUTES: { target: '.edit.timinutes' }, | |
EDIT_NOTIFICATIONS: { target: '.edit.notifications' } | |
}, | |
states: { | |
read: {}, | |
edit: { | |
initial: 'threshold', | |
on: { | |
SAVE: { target: 'saving' } | |
}, | |
states: { | |
threshold: { | |
on: { | |
NEXT: {target: 'timinutes'}, | |
UPDATE_THRESHOLD: { | |
actions: ['updateThreshold'] | |
} | |
} | |
}, | |
timinutes: { | |
on: { | |
NEXT: {target: 'notifications'}, | |
UPDATE_OCCURRENCE: { | |
actions: ['updateOccurrence'] | |
}, | |
UPDATE_DURATION: { | |
actions: ['updateDuration'] | |
} | |
} | |
}, | |
notifications: { | |
} | |
} | |
}, | |
saving: { | |
on: { | |
SUCCESS: 'saved' | |
} | |
}, | |
saved: { | |
entry: 'updateOriginals', | |
after: { | |
1000: 'read' | |
} | |
} | |
} | |
}, | |
} | |
} | |
} | |
}, { | |
guards: { | |
isChanged: () => false | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment