Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. // Available variables:
  2. // - Machine
  3. // - interpret
  4. // - assign
  5. // - send
  6. // - sendParent
  7. // - spawn
  8. // - raise
  9. // - actions
  10. // - XState (all XState exports)
  11.  
  12. const compilationMachine = Machine({
  13. id: 'compilation',
  14. initial: 'idle',
  15. context: {
  16. errors: []
  17. },
  18. states: {
  19. idle: {
  20. on: {
  21. RUN: 'running'
  22. }
  23. },
  24. running: {
  25. on: {
  26. DONE: 'done'
  27. }
  28. },
  29. done: {
  30. type: 'final'
  31. }
  32. }
  33. });
  34.  
  35. const compilerMachine = Machine({
  36. id: 'compiler',
  37. initial: "initializing",
  38. context: {
  39. compilations: []
  40. },
  41. states: {
  42. initializing: {
  43. entry: assign({
  44. compilations: (ctx, e) => {
  45. return ctx.compilations.map(c => ({
  46. ...c,
  47. ref: spawn(compilationMachine.withContext(c))
  48. }));
  49. },
  50. }),
  51. },
  52. running: {},
  53. completed: {}
  54. },
  55. on: {
  56. "MARK.running": {
  57. actions: ctx => {
  58. ctx.compilations.forEach(c => c.ref.send("RUN"));
  59. }
  60. }
  61. }
  62. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement