Created
March 29, 2021 20:45
-
-
Save GABAnich/e70817e44a1dae3b414360eaf29be595 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 fetchMachine = Machine({ | |
id: 'vacation', | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
REQUEST: 'waiting_for_manager_approve' | |
} | |
}, | |
waiting_for_manager_approve: { | |
on: { | |
MANAGER_APPROVE: 'waiting_for_team_approve', | |
MANAGER_REJECT: 'rejected' | |
} | |
}, | |
waiting_for_team_approve: { | |
on: { | |
TEAM_APPROVE: { | |
target: 'approved', | |
cond: 'teamApprove' | |
}, | |
TEAM_REJECT: 'rejected' | |
} | |
}, | |
approved: { | |
type: 'final' | |
}, | |
rejected: { | |
type: 'final' | |
} | |
}, | |
guards: { | |
teamApprove: () => { | |
let count = 0; // get count from DB | |
count++; | |
if (count < 6) return false; | |
return true; | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment