Skip to content

Instantly share code, notes, and snippets.

@edamamegreen
Last active May 3, 2018 23:07
Show Gist options
  • Save edamamegreen/af303040afa11d7c7dc10dc4a13abaf7 to your computer and use it in GitHub Desktop.
Save edamamegreen/af303040afa11d7c7dc10dc4a13abaf7 to your computer and use it in GitHub Desktop.
Product Availability*
View an interactive version of this gist on statepen.
Product Availability*
# An inventory check might be triggered by a page load or refresh.
check inventory -> Product Availability
# The state while waiting for a response from the server.
Check inventory*
# Possible responses from the server.
in stock -> In Stock
backordered -> Backordered
special order -> Special Order
nil -> No Data
No Data
In Stock
Backordered
Special Order
function availability(state){
var urls = new Map('Check inventory', "http://www.nickivance.com/img/loading.png",
'No Data', "http://www.nickivance.com/img/No_Data.png"
if (state == 'Check inventory') {
return $('img',
{src: "http://www.nickivance.com/img/loading.png",
style: {width: "400px"}})
}
if (state == 'No Data') {
return $('img',
{src: "http://www.nickivance.com/img/No_Data.png",
style: {width: "400px"}})
}
if (state == 'In Stock') {
return $('img',
{src: "http://www.nickivance.com/img/In Stock.png",
style: {width: "400px"}})
}
if (state == 'Backordered') {
return $('img',
{src: "http://www.nickivance.com/img/Backordered.png",
style: {width: "400px"}})
}
if (state == 'Special Order') {
return $('img',
{src: "http://www.nickivance.com/img/Special_Order.png",
style: {width: "400px"}})
}
}
//A function that draws all of our lights, based on the statechart
function render({active_states}){
var active_state = active_states[0].name;
return $('div', {style: {display: 'flex',
flexDirection: 'column',
paddingTop: `20px`,
justifyContent: 'center',
height: `100%`}},
$('img', {src: "http://www.nickivance.com/img/Base.png",
style: {width: "400px"}}),
availability(active_state)
)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment