Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const spine = Machine(
- {
- id: 'wishboneMachine',
- initial: 'apiGateway',
- context: {},
- strict: true,
- states: {
- apiGateway: {
- initial: 'listen',
- states: {
- listen: {
- on: {
- CONNECT: 'connect',
- CREATE_STORE: 'createStore',
- POOL_ACTION: 'poolAction',
- SUBSCRIBE: 'subscribe',
- UNSUBSCRIBE: 'unsubscribe',
- GET_STATE: 'getState',
- DISCONNECT: 'disconnect',
- },
- },
- connect: {
- invoke: {
- src: 'connect',
- onDone: 'apiSuccess',
- onError: 'onError',
- },
- },
- createStore: {
- invoke: {
- src: 'createStore',
- onDone: '#committer',
- onError: 'onError',
- },
- },
- poolAction: {
- invoke: {
- src: 'poolAction',
- onDone: '#committer',
- onError: 'onError',
- },
- },
- subscribe: {
- invoke: {
- src: 'subscribe',
- onDone: 'apiSuccess',
- onError: 'onError',
- },
- },
- unsubscribe: {
- invoke: {
- src: 'unsubscribe',
- onDone: 'apiSuccess',
- onError: 'onError',
- },
- },
- getState: {
- invoke: {
- src: 'getState',
- onDone: 'apiSuccess',
- onError: 'onError',
- },
- },
- disconnect: {
- invoke: {
- src: 'disconnect',
- onDone: 'apiSuccess',
- onError: 'onError',
- },
- },
- apiSuccess: {
- on: { '': '#success' },
- },
- onError: {
- on: { '': '#onError' },
- },
- },
- },
- committer: {
- id: 'committer',
- initial: 'commitCreator',
- states: {
- commitCreator: {
- initial: 'statePoolHasActions',
- states: {
- statePoolHasActions: {
- invoke: {
- src: 'statePoolHasActions',
- onDone: { target: 'isActions', actions: 'isActions' },
- },
- },
- isActions: {
- // "Transient" state
- on: {
- '': [
- { target: 'stateAcquireStoreLock', cond: 'isCommitable' },
- { target: '#success', cond: 'isUncommitable' },
- ],
- },
- },
- stateAcquireStoreLock: {
- invoke: {
- src: 'stateAcquireStoreLock',
- onDone: 'commitStarter',
- },
- },
- commitStarter: {
- invoke: {
- src: 'commitStarter',
- onDone: 'covenantRunner',
- },
- },
- covenantRunner: {
- invoke: {
- src: 'covenantRunner',
- onDone: 'commitGenerator',
- },
- },
- commitGenerator: {
- invoke: {
- src: 'commitGenerator',
- onDone: 'commitWriter',
- },
- },
- commitWriter: {
- invoke: {
- src: 'commitWriter',
- onDone: 'refineActionPool',
- },
- },
- refineActionPool: {
- invoke: {
- src: 'poolRefiner',
- onDone: 'releaseLock',
- },
- },
- releaseLock: {
- invoke: {
- src: 'releaseLock',
- onDone: 'commitSuccess',
- },
- },
- commitSuccess: {
- type: 'final',
- },
- },
- onDone: 'commitMaintenance',
- },
- commitMaintenance: {
- type: 'parallel',
- states: {
- storeCreation: {
- initial: 'createStores',
- states: {
- createStores: {
- invoke: {
- src: 'storeCreator',
- onDone: {
- target: 'storeCreationSuccess', //TODO: What do we want to do with the report?
- },
- },
- },
- storeCreationSuccess: {
- type: 'final',
- },
- },
- },
- storeTermination: {
- initial: 'killStores',
- states: {
- killStores: {
- invoke: {
- src: 'storeKiller',
- onDone: {
- target: 'storeTerminationSuccess', //TODO: What do we want to do with the report?
- },
- },
- },
- storeTerminationSuccess: {
- type: 'final',
- },
- },
- },
- notifySubscribers: {
- initial: 'notifySubscribers',
- states: {
- notifySubscribers: {
- invoke: {
- src: 'notifySubscribers',
- onDone: {
- target: 'notifySubscribersSuccess', //TODO: What do we want to do with the report?
- },
- },
- },
- notifySubscribersSuccess: {
- type: 'final',
- },
- },
- },
- },
- onDone: 'linker',
- },
- linker: {
- invoke: {
- src: 'linker',
- onDone: 'endCommit',
- },
- },
- endCommit: {
- invoke: {
- src: 'commitTerminator',
- onDone: 'commitCreator',
- },
- },
- },
- },
- success: {
- id: 'success',
- type: 'final',
- },
- onError: {
- id: 'onError',
- type: 'final',
- },
- },
- },
- {
- // FOR VISUALIZATION PURPOSES ONLY
- guards: {
- isCommitable: context => context.isActions < 2,
- isUncommitable: context => context.isActions > 1,
- },
- actions: {
- isActions: assign({
- isActions: context => {
- return !!context.isActions + true
- },
- }),
- },
- }
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement