Last active
February 14, 2020 16:54
-
-
Save rsoares/4dc7428f95c329da107488677a62548b 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 filesAppMachine = Machine({ | |
id: 'filesApp', | |
initial: 'idle', | |
context: { | |
files: [] | |
}, | |
states: { | |
idle: { | |
on: { | |
FETCH_ATTACHMENTS: 'loading' | |
} | |
}, | |
loading: { | |
on: { | |
SUCCESS: 'list', | |
ERROR: 'idle' | |
} | |
}, | |
deleting: { | |
on: { | |
SUCCESS: 'list', | |
ERROR: 'list' | |
} | |
}, | |
updating: { | |
on: { | |
SUCCESS: 'list', | |
ERROR: 'list' | |
} | |
}, | |
setFiles: { | |
on: { MODAL_OPEN: 'uploadFiles' } | |
}, | |
createAttachment: { | |
on: { | |
SUCCESS: { | |
target: 'list', | |
actions: assign({ | |
files: (context, event) => context.files.concat('|') | |
}) | |
}, | |
ERROR: 'uploadFiles' | |
} | |
}, | |
list: { | |
on: { | |
EMPTY: 'emptyList', | |
HYDRATE: 'hydratedList' | |
} | |
}, | |
emptyList: { | |
on: { | |
SELECT_FILES: 'setFiles' | |
} | |
}, | |
hydratedList: { | |
type: 'final', | |
on: { | |
SELECT_FILES: 'setFiles' | |
} | |
}, | |
uploadFiles: { | |
on: { | |
SUCCESS: 'doneUploading', | |
ERROR: 'doneUploading' | |
} | |
}, | |
doneUploading: { | |
on: { | |
ATTACH_FILES: 'createAttachment' | |
} | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment