Last active
January 26, 2021 19:59
-
-
Save kazagkazag/946cf72ae052169a30895e8aa92e5aa9 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 photoBook = Machine({ | |
id: 'photoBook', | |
initial: 'initialSettings', | |
context: { | |
success: null, | |
fileHandler: null, | |
title: null | |
}, | |
states: { | |
initialSettings: { | |
on: { | |
SELECT_NO_OF_PAGES: 'composing' | |
} | |
}, | |
composing: { | |
id: 'composing', | |
initial: 'selectPage', | |
context: { | |
fileHandler: null, | |
success: null | |
}, | |
states: { | |
selectPage: { | |
on: { | |
SELECT_PAGE: 'selectFile' | |
}, | |
}, | |
selectFile: { | |
on: { | |
SELECTED: 'photoUpload' | |
} | |
}, | |
photoUpload: { | |
after: { | |
1000: 'failure' | |
}, | |
invoke: { | |
src: () => new Promise((res, rej) => { | |
setTimeout(() => { | |
res({ | |
fileHandler: 'some file' | |
}) | |
}, 500) | |
}), | |
onDone: { | |
target: 'details', | |
actions: assign({ | |
fileHandler: (ctx, e) => e.data.fileHandler, | |
success: true | |
}) | |
}, | |
onError: { | |
target: 'failure' | |
} | |
} | |
}, | |
failure: { | |
on: { | |
RETRY: 'selectFile' | |
} | |
}, | |
details: { | |
on: { | |
SAVE: '#composing' | |
}, | |
type: 'parallel', | |
states: { | |
editTitle: { | |
initial: 'read', | |
states: { | |
edit: { | |
on: { | |
SAVE_TITLE: 'read' | |
} | |
}, | |
read: { | |
on: { | |
EDIT_TITLE: 'edit' | |
} | |
} | |
} | |
}, | |
editDesc: { | |
initial: 'read', | |
states: { | |
edit: { | |
on: { | |
SAVE_DESC: 'read' | |
} | |
}, | |
read: { | |
on: { | |
EDIT_DESC: 'edit' | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment