Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None | 0 0
  1. const spine = Machine(
  2. {
  3. id: 'wishboneMachine',
  4. initial: 'apiGateway',
  5. context: {},
  6. strict: true,
  7. states: {
  8. apiGateway: {
  9. initial: 'listen',
  10. states: {
  11. listen: {
  12. on: {
  13. CONNECT: 'connect',
  14. CREATE_STORE: 'createStore',
  15. POOL_ACTION: 'poolAction',
  16. SUBSCRIBE: 'subscribe',
  17. UNSUBSCRIBE: 'unsubscribe',
  18. GET_STATE: 'getState',
  19. DISCONNECT: 'disconnect',
  20. },
  21. },
  22. connect: {
  23. invoke: {
  24. src: 'connect',
  25. onDone: 'apiSuccess',
  26. onError: 'onError',
  27. },
  28. },
  29. createStore: {
  30. invoke: {
  31. src: 'createStore',
  32. onDone: '#committer',
  33. onError: 'onError',
  34. },
  35. },
  36. poolAction: {
  37. invoke: {
  38. src: 'poolAction',
  39. onDone: '#committer',
  40. onError: 'onError',
  41. },
  42. },
  43. subscribe: {
  44. invoke: {
  45. src: 'subscribe',
  46. onDone: 'apiSuccess',
  47. onError: 'onError',
  48. },
  49. },
  50. unsubscribe: {
  51. invoke: {
  52. src: 'unsubscribe',
  53. onDone: 'apiSuccess',
  54. onError: 'onError',
  55. },
  56. },
  57. getState: {
  58. invoke: {
  59. src: 'getState',
  60. onDone: 'apiSuccess',
  61. onError: 'onError',
  62. },
  63. },
  64. disconnect: {
  65. invoke: {
  66. src: 'disconnect',
  67. onDone: 'apiSuccess',
  68. onError: 'onError',
  69. },
  70. },
  71. apiSuccess: {
  72. on: { '': '#success' },
  73. },
  74. onError: {
  75. on: { '': '#onError' },
  76. },
  77. },
  78. },
  79.  
  80. committer: {
  81. id: 'committer',
  82. initial: 'commitCreator',
  83. states: {
  84. commitCreator: {
  85. initial: 'statePoolHasActions',
  86. states: {
  87. statePoolHasActions: {
  88. invoke: {
  89. src: 'statePoolHasActions',
  90. onDone: { target: 'isActions', actions: 'isActions' },
  91. },
  92. },
  93. isActions: {
  94. // "Transient" state
  95. on: {
  96. '': [
  97. { target: 'stateAcquireStoreLock', cond: 'isCommitable' },
  98. { target: '#success', cond: 'isUncommitable' },
  99. ],
  100. },
  101. },
  102. stateAcquireStoreLock: {
  103. invoke: {
  104. src: 'stateAcquireStoreLock',
  105. onDone: 'commitStarter',
  106. },
  107. },
  108. commitStarter: {
  109. invoke: {
  110. src: 'commitStarter',
  111. onDone: 'covenantRunner',
  112. },
  113. },
  114. covenantRunner: {
  115. invoke: {
  116. src: 'covenantRunner',
  117. onDone: 'commitGenerator',
  118. },
  119. },
  120. commitGenerator: {
  121. invoke: {
  122. src: 'commitGenerator',
  123. onDone: 'commitWriter',
  124. },
  125. },
  126. commitWriter: {
  127. invoke: {
  128. src: 'commitWriter',
  129. onDone: 'refineActionPool',
  130. },
  131. },
  132. refineActionPool: {
  133. invoke: {
  134. src: 'poolRefiner',
  135. onDone: 'releaseLock',
  136. },
  137. },
  138. releaseLock: {
  139. invoke: {
  140. src: 'releaseLock',
  141. onDone: 'commitSuccess',
  142. },
  143. },
  144. commitSuccess: {
  145. type: 'final',
  146. },
  147. },
  148. onDone: 'commitMaintenance',
  149. },
  150. commitMaintenance: {
  151. type: 'parallel',
  152. states: {
  153. storeCreation: {
  154. initial: 'createStores',
  155. states: {
  156. createStores: {
  157. invoke: {
  158. src: 'storeCreator',
  159. onDone: {
  160. target: 'storeCreationSuccess', //TODO: What do we want to do with the report?
  161. },
  162. },
  163. },
  164. storeCreationSuccess: {
  165. type: 'final',
  166. },
  167. },
  168. },
  169. storeTermination: {
  170. initial: 'killStores',
  171. states: {
  172. killStores: {
  173. invoke: {
  174. src: 'storeKiller',
  175. onDone: {
  176. target: 'storeTerminationSuccess', //TODO: What do we want to do with the report?
  177. },
  178. },
  179. },
  180. storeTerminationSuccess: {
  181. type: 'final',
  182. },
  183. },
  184. },
  185.  
  186. notifySubscribers: {
  187. initial: 'notifySubscribers',
  188. states: {
  189. notifySubscribers: {
  190. invoke: {
  191. src: 'notifySubscribers',
  192. onDone: {
  193. target: 'notifySubscribersSuccess', //TODO: What do we want to do with the report?
  194. },
  195. },
  196. },
  197. notifySubscribersSuccess: {
  198. type: 'final',
  199. },
  200. },
  201. },
  202. },
  203. onDone: 'linker',
  204. },
  205. linker: {
  206. invoke: {
  207. src: 'linker',
  208. onDone: 'endCommit',
  209. },
  210. },
  211. endCommit: {
  212. invoke: {
  213. src: 'commitTerminator',
  214. onDone: 'commitCreator',
  215. },
  216. },
  217. },
  218. },
  219.  
  220. success: {
  221. id: 'success',
  222. type: 'final',
  223. },
  224. onError: {
  225. id: 'onError',
  226. type: 'final',
  227. },
  228. },
  229. },
  230. {
  231. // FOR VISUALIZATION PURPOSES ONLY
  232. guards: {
  233. isCommitable: context => context.isActions < 2,
  234. isUncommitable: context => context.isActions > 1,
  235. },
  236. actions: {
  237. isActions: assign({
  238. isActions: context => {
  239. return !!context.isActions + true
  240. },
  241. }),
  242. },
  243. }
  244. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement