Last active
February 9, 2020 00:27
-
-
Save barbados-clemens/dbff7ab7affae922b6bc0ca461906a01 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
// https://xstate.js.org/viz/?gist=dbff7ab7affae922b6bc0ca461906a01 | |
// { | |
// "type": "USER_ADD", | |
// "user": { | |
// "name": "something", | |
// "isPending": true, | |
// "drafted": [] | |
// } | |
// } | |
const {log} = actions; | |
const hasUsers = ({users}) => !!users | |
const hasPendingUsers = ({users}) => !users.filter(u => u.isPending).length > 0; | |
const addUser = assign({ | |
users: (ctx, event) => { | |
return [...ctx.users, event.user] | |
} | |
}); | |
const fetchMachine = Machine({ | |
id: 'league', | |
initial: 'created', | |
context: { | |
name: '', | |
users: [ | |
{name: '', isPending: false, drafted: [] } | |
] | |
}, | |
states: { | |
created: { | |
on: { | |
'': { | |
target: 'pendingInvites', | |
cond: hasUsers | |
}, | |
} | |
}, | |
pendingInvites: { | |
on: { | |
'': { | |
target: 'ready', | |
cond: hasPendingUsers | |
} | |
} | |
}, | |
ready: { | |
on: { | |
'START': { | |
target: 'drafting' | |
} | |
} | |
}, | |
drafting: { | |
on: { | |
// should start drafting machine | |
'DONE': { | |
target: 'settled' | |
} | |
} | |
}, | |
settled: { | |
on: { | |
'FINISHED': { | |
target: 'closed' | |
} | |
} | |
}, | |
closed: { | |
}, | |
}, | |
on: { | |
'USER_ADD': { | |
target: 'pendingInvites', | |
actions: addUser | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment