Last active
September 8, 2019 20:38
-
-
Save wardpeet/b675a95cceeb5de32d356ed2bfd1e038 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
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