Last active
August 25, 2020 15:41
-
-
Save rix501/733ef797bc484f0c9d62c11c1f159de9 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: 'bookPurchase', | |
| initial: 'idle', | |
| states: { | |
| idle: { | |
| always: [ | |
| { target: 'canRead', cond: 'isCanRead' }, | |
| { target: 'canReadForFree.addToLibrary', cond: 'isAddToLibrary' }, | |
| { target: 'canReadForFree', cond: 'isCanReadForFree' }, | |
| { target: 'borrow.borrowing', cond: 'isBorrowing' }, | |
| { target: 'borrow', cond: 'isBorrow' }, | |
| { target: 'canBuyInProgram.purchase', cond: 'isPurchaseInProgram' }, | |
| { target: 'canBuyInProgram', cond: 'isCanBuyInProgram' }, | |
| { target: 'canBuy.purchase', cond: 'isPurchase' }, | |
| { target: 'canBuy' } | |
| ] | |
| }, | |
| canBuy: { | |
| initial: 'canBuy', | |
| states: { | |
| canBuy: { | |
| on: { | |
| ShowPurchase: 'purchase' | |
| } | |
| }, | |
| purchase: { | |
| on: { | |
| Purchasing: 'purchasing' | |
| } | |
| }, | |
| purchasing: { | |
| invoke: { | |
| id: 'submitPurchase', | |
| src: (context) => buyBook(context.book, context.buyReftag), | |
| onDone: 'purchased', | |
| onError: 'errorPurchasing' | |
| } | |
| }, | |
| errorPurchasing: { | |
| entry: ['onErrorPurchase'] | |
| }, | |
| purchased: { | |
| initial: 'purchased', | |
| states: { | |
| cancel: { | |
| entry: ['onModalOpen'], | |
| on: { | |
| Canceling: 'canceling', | |
| HideCancel: 'purchased' | |
| } | |
| }, | |
| canceling: { | |
| invoke: { | |
| id: 'submitCancel', | |
| src: (context) => cancelBookOrder(context.book, context.buyReftag), | |
| onDone: 'canceled', | |
| onError: 'errorCanceling' | |
| } | |
| }, | |
| errorCanceling: { | |
| entry: ['onErrorCancelPurchase'], | |
| on: { | |
| Canceling: 'canceling', | |
| HideCancel: 'purchased' | |
| } | |
| }, | |
| canceled: { | |
| entry: ['onCancelPurchase', 'onModalClose'], | |
| on: { | |
| Purchasing: '..purchasing' | |
| } | |
| }, | |
| purchased: { | |
| entry: ['onSuccessPurchase'], | |
| on: { | |
| ShowCancel: 'cancel' | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }, | |
| canBuyInProgram: { | |
| initial: 'canBuyInProgram', | |
| states: { | |
| canBuyInProgram: { | |
| on: { | |
| ShowPurchaseInProgram: 'purchase' | |
| } | |
| }, | |
| purchase: { | |
| on: { | |
| Purchasing: 'purchasing' | |
| } | |
| }, | |
| purchasing: { | |
| invoke: { | |
| id: 'submitPurchase', | |
| src: (context) => buyBook(context.book, context.buyReftag), | |
| onDone: 'purchased', | |
| onError: 'errorPurchasing' | |
| } | |
| }, | |
| errorPurchasing: { | |
| entry: ['onErrorPurchase'] | |
| }, | |
| purchased: { | |
| initial: 'purchased', | |
| states: { | |
| cancel: { | |
| entry: ['onModalOpen'], | |
| on: { | |
| Canceling: 'canceling', | |
| HideCancel: 'purchased' | |
| } | |
| }, | |
| canceling: { | |
| invoke: { | |
| id: 'submitCancel', | |
| src: (context) => cancelBookOrder(context.book, context.buyReftag), | |
| onDone: 'canceled', | |
| onError: 'errorCanceling' | |
| } | |
| }, | |
| errorCanceling: { | |
| entry: ['onErrorCancelPurchase'], | |
| on: { | |
| Canceling: 'canceling', | |
| HideCancel: 'purchased' | |
| } | |
| }, | |
| canceled: { | |
| entry: ['onCancelPurchase', 'onModalClose'], | |
| on: { | |
| Purchasing: '..purchasing' | |
| } | |
| }, | |
| purchased: { | |
| entry: ['onSuccessPurchase'], | |
| on: { | |
| ShowCancel: 'cancel' | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }, | |
| borrow: { | |
| initial: 'borrow', | |
| states: { | |
| borrow: { | |
| on: { | |
| Borrowing: 'borrowing' | |
| } | |
| }, | |
| borrowing: { | |
| invoke: { | |
| id: 'submitBorrow', | |
| src: (context) => buyBook(context.book, context.buyReftag), | |
| onDone: 'borrowed', | |
| onError: 'errorBorrowing' | |
| } | |
| }, | |
| errorBorrowing: { | |
| entry: ['onErrorPurchase'], | |
| on: { | |
| Borrowing: 'borrowing' | |
| } | |
| }, | |
| borrowed: { | |
| entry: ['onSuccessPurchase'] | |
| } | |
| } | |
| }, | |
| canReadForFree: { | |
| initial: 'canReadForFree', | |
| states: { | |
| canReadForFree: { | |
| on: { | |
| ShowReadFree: 'addToLibrary' | |
| } | |
| }, | |
| addToLibrary: { | |
| on: { | |
| AddingToLibrary: 'addingToLibrary' | |
| } | |
| }, | |
| addingToLibrary: { | |
| invoke: { | |
| id: 'submitAddToLibrary', | |
| src: (context) => buyBook(context.book, context.buyReftag), | |
| onDone: 'addedToLibrary', | |
| onError: 'errorAddingToLibrary' | |
| } | |
| }, | |
| errorAddingToLibrary: { | |
| entry: ['onErrorPurchase'], | |
| on: { | |
| AddingToLibrary: 'addingToLibrary' | |
| } | |
| }, | |
| addedToLibrary: { | |
| entry: ['onSuccessPurchase'] | |
| } | |
| } | |
| }, | |
| canRead: { | |
| initial: 'canRead', | |
| states: { | |
| canRead: {} | |
| } | |
| } | |
| }, | |
| on: { | |
| UpdateContext: { | |
| actions: ['updateContext'] | |
| } | |
| } | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment