Skip to content

Instantly share code, notes, and snippets.

@pavankataria
Created January 15, 2021 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavankataria/47c2b1cdd6257d4ed90f917e74463cdd to your computer and use it in GitHub Desktop.
Save pavankataria/47c2b1cdd6257d4ed90f917e74463cdd to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const addToUpload = assign({
uploadAmount: (context, event) => context.uploadAmount + 2
});
const addToDownload = assign({
downloadAmount: (context, event) => context.downloadAmount + 2
});
const fileMachine = Machine({
id: 'file',
type: 'parallel',
context: {
uploadAmount: 0,
downloadAmount: 0,
},
states: {
upload: {
initial: 'idle',
states: {
idle: {
on: {
INIT_UPLOAD: {
target: 'pending',
actions: 'addToUpload'
}
}
},
pending: {
on: {
UPLOAD_MORE: {
target: 'pending',
actions: 'addToUpload'
}
}
},
success: {}
}
},
download: {
initial: 'idle',
states: {
idle: {
on: {
INIT_DOWNLOAD: {
target: 'pending',
actions: 'addToDownload'
}
}
},
pending: {
on: {
DOWNLOAD_MORE: {
target: 'pending',
actions: 'addToDownload'
}
}
},
success: {}
}
}
}
},{
actions: { addToUpload, addToDownload }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment