Last active
July 24, 2020 17:29
-
-
Save bholmesdev/cdf3459192ea26ab34f85fef8e03fa55 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
// export type loadingStates = 'loadingCart' | 'loadValidateShipping' | |
const loadingSideEffects = { | |
loadingCart: { | |
invoke: { | |
src: 'loadingCart', | |
onDone: [{ | |
target: 'idleCart', | |
cond: (_, event) => event.data, | |
actions: [ | |
'analyticsPlz', | |
assign({ | |
cart: (_, event) => event.data | |
}) | |
] | |
},{ | |
target: 'emptyCart' | |
}], | |
onError: 'idleCart' | |
} | |
}, | |
validateShipping: { | |
invoke: { | |
src: 'validateShipping', | |
onDone: { | |
target: 'validatedCart', | |
actions: assign({ | |
shipping: (_, event) => event.data | |
}) | |
}, | |
onError: 'idleCart' | |
} | |
}, | |
} | |
const fetchMachine = Machine({ | |
id: 'cart', | |
initial: 'loadingCart', | |
context: { | |
hasFinancing: false, | |
paymentAvailable: false, | |
cart: [] | |
}, | |
states: { | |
...loadingSideEffects, | |
idleCart: { | |
on: { | |
VALIDATE_SHIPPING_INFO: 'validateShipping' | |
} | |
}, | |
emptyCart: { | |
on: { | |
REFRESH: 'loadingCart' | |
} | |
}, | |
validatedCart: { | |
// tax calculated | |
// shipping calculated | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment