Skip to content

Instantly share code, notes, and snippets.

@wardpeet
Last active September 8, 2019 20:38
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 wardpeet/b675a95cceeb5de32d356ed2bfd1e038 to your computer and use it in GitHub Desktop.
Save wardpeet/b675a95cceeb5de32d356ed2bfd1e038 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const inProcessStates = {
states: {
PROCESSING_DATA: {
// I still need to figure out how to do activities correctly, ordering isn't correct as I can't pass this activity
// to it's children
activities: [{
type: 'activity',
message: 'Reprocessing static & page queries'
}],
invoke: {
src: 'runQueries',
onDone: {
target: 'DONE',
actions: assign({
queryIds: [],
})
}
},
},
PROCESSING_WEBPACK: {
entry: ['buildCode'],
activities: [{
type: 'activity',
message: 'Rebuilding production JavaScript and CSS bundles'
}],
on: {
SUCCESS: {
target: 'DONE',
actions: assign({
prevWebpackHashMap: (_, event) => event.chunkHashes,
pagesToBuild: (_, event) => event.pages,
})
}
}
},
DONE: {
on: {
'': [
{
target: '#write-pages',
cond: (ctx) => ctx.pagesToBuild && ctx.pagesToBuild.length,
},
{
target: '#build-complete',
}
]
}
}
},
}
const incBuildMachine = Machine({
id: 'inc-build',
initial: 'PENDING',
context: {
program: null,
pagesToBuild: [],
queryIds: [],
prevWebpackHashMap: new Map(),
reporter: null,
},
states: {
PENDING: {
invoke: {
src: 'setup',
onDone: {
target: 'READY',
}
}
},
READY: {
initial: 'PENDING',
entry: ['notifyListeners'],
states: {
PENDING: {
exit: ['notifyReady'],
on: {
BOOTSTRAP_FINISHED: {
target: 'IDLE',
actions: assign({ prevWebpackHashMap: (_, event) => event.chunkHashes }),
},
}
},
IDLE: {
on: {
DATA_CHANGE: {
target: 'PROCESS.PROCESSING_DATA',
actions: assign({
queryIds: (ctx, event) => Array.from(new Set((ctx.queryIds || []).concat(event.queryIds)))
})
},
CODE_CHANGE: {
target: 'PROCESS.PROCESSING_WEBPACK',
},
}
},
PROCESS: inProcessStates,
WRITE_PAGES: {
id: 'write-pages',
invoke: {
src: 'writePages',
onDone: {
target: 'BUILD_COMPLETE',
}
},
},
BUILD_COMPLETE: {
id: 'build-complete',
invoke: {
src: 'buildDone',
onDone: {
target: 'IDLE',
}
},
}
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment