Skip to content

Instantly share code, notes, and snippets.

@carlosvillu
Created April 2, 2020 14:50
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 carlosvillu/53bbc285604bb5c20b1bb48373e3c2d7 to your computer and use it in GitHub Desktop.
Save carlosvillu/53bbc285604bb5c20b1bb48373e3c2d7 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'trackingMachine',
initial: 'idle',
states: {
idle: {
on: {
SHOW_BANNER: {
target: 'banner',
cond: 'isNotAVisitRejected'
},
CLICK_LINK: {
target: 'modal',
cond: 'isNotAVisitRejected'
},
VISIT_REJECTED: {
target: 'visitReject',
cond: 'isAVisitRejected'
}
}
},
banner: {
on: {
REVIEW: {
target: 'modal'
},
ACCEPT: {
target: 'accepted'
}
}
},
modal: {
on: {
ACCEPT: {
target: 'accepted'
},
REJECT: {
target: 'rejected'
}
}
},
accepted: {
type: 'final',
entry: 'trackAccepted'
},
rejected: {
type: 'final',
entry: 'trackRejected'
},
visitReject: {
initial: 'idle',
states: {
idle: {
on: {
'': {
target: 'trackVisitRejected',
cond: 'notTrackVisitRejectOnSession'
}
}
},
trackVisitRejected: {
type: 'final'
}
}
}
}
},
{
actions: {
trackAccepted: () => {},
trackRejected: () => {}
},
guards: {
isNotAVisitRejected: () => {
return false
},
isAVisitRejected: () => {
return true
},
notTrackVisitRejectOnSession: () => {
return true
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment