Skip to content

Instantly share code, notes, and snippets.

@JamesTeague
Created February 25, 2020 14:45
Show Gist options
  • Save JamesTeague/c5fe4b02be8d4847eae3478ec37a53fc to your computer and use it in GitHub Desktop.
Save JamesTeague/c5fe4b02be8d4847eae3478ec37a53fc to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const addLayer = assign({
layersCount: (context, event) => context.layersCount + 1
});
const integratingDocs = {
initial: 'integrating-docs',
states: {
"integrating-docs" : {
on: {
PROVIDER_SELECT: 'connecting-to-provider'
}
},
"connecting-to-provider": {
on: {
CANCEL: 'integrating-docs',
// TODO - get this mocked
ERROR: '',
SUCCESS: 'selecting-docs',
}
},
"selecting-docs": {
on: {
DOC_SELECTED: 'syncing-docs',
CANCEL: 'integrating-docs',
}
},
"syncing-docs": {
on: {
NEXT: {
target: '../viewing-gifs',
// TODO - add parameter for file count
action: 'addLayer'
},
// TODO - Not this.
CANCEL: '../initialized'
}
}
}
};
const fetchMachine = Machine({
id: 'activation',
initial: 'selecting-provider',
context: {
termsAdded: false,
mapCenter: [0,0],
boundingBox: [],
layersCount: 0
},
states: {
initialized: {
on: {
NEXT: 'non-accepted'
}
},
"non-accepted": {
on: {
NEXT: 'viewing-setup'
}
},
"viewing-setup": {
on: {
NEXT: 'fitting-project'
}
},
"fitting-project": {
on: {
NEXT: 'adjusting-bounds'
}
},
"adjusting-bounds": {
on: {
NEXT: 'naming-project',
PREVIOUS: 'fitting-project'
}
},
"naming-project":{
on: {
NEXT: 'selecting-provider'
}
},
"selecting-provider": {
on: {
SKIP: 'viewing-gifs',
ADD: {
target: 'viewing-gifs',
actions: 'addLayer'
}
},
...integratingDocs,
},
"viewing-gifs": {
on: {
NEXT: 'adding-map-shit'
}
},
"adding-map-shit": {
on: {
ADD_LAYER: [
{
target: 'selecting-layer',
cond: (ctx) => ctx.layersCount > 0
},
{
target: 'selecting-provider'
}
],
ADD_POST: 'adding-post'
}
},
"selecting-layer": {
on: {
SELECT: 'calibrating'
}
},
"adding-post": {
on: {
FINISH: 'adding-project-info'
}
},
"calibrating": {
on: {
FINISH: 'adding-project-info'
}
},
"adding-project-info": {
on: {
FINISH: 'finish'
}
},
finish: {
type: 'final'
}
}
},{
actions:{ addLayer}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment