Last active
June 30, 2023 20:02
-
-
Save vunderkind/92a0f14497a40f57ed793269780deff2 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
async function invokeFetch(context) { | |
console.log(context) | |
const { documentUrl } = context; | |
return await fetch(`https://google.com`) | |
} | |
const DocMachine = Machine({ | |
id: 'doc-chat', | |
initial: 'idle', | |
context: { | |
url: null, | |
title: null, | |
}, | |
states: { | |
idle: {}, | |
selected: { | |
initial: 'loading', | |
states: { | |
loading: { | |
invoke: { | |
id: 'get-doc', | |
src: invokeFetch, | |
onDone: { | |
target: 'loaded', | |
action: assign({ | |
documentUrl: (context, event) => event.url | |
}), | |
}, | |
onError: 'error' | |
}, | |
}, | |
'loaded': {}, | |
'error': {} | |
} | |
} | |
}, | |
on: { | |
SELECT: { | |
target: '.selected', | |
action: assign({ | |
documentUrl: (context, event) => event.url | |
}), | |
}, | |
DESELECT: { | |
target: '.idle', | |
action: assign({ | |
documentUrl: () => null, | |
}), | |
}, | |
}, | |
}); | |
const docSelectEvent = { | |
type: 'SELECT', | |
url: 'reactjs' | |
} | |
const docDeselectEvent = { | |
type: 'DESELECT', | |
url: 'meh' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment