Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidkpiano/durable-entities-xstate
XState + Durable Entities = 🚀
https://github.com/davidkpiano/durable-entities-xstate
Last synced: about 2 months ago
JSON representation
XState + Durable Entities = 🚀
- Host: GitHub
- URL: https://github.com/davidkpiano/durable-entities-xstate
- Owner: davidkpiano
- License: mit
- Created: 2020-10-06T00:25:56.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2020-11-09T15:29:56.000Z (almost 4 years ago)
- Last Synced: 2024-05-01T21:06:01.929Z (5 months ago)
- Language: TypeScript
- Size: 13.7 KB
- Stars: 54
- Watchers: 4
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - durable-entities-xstate
README
# durable-entities-xstate
XState + Durable Entities = 🚀
## Prerequisites
- Ensure you have all the prerequisites satisfied [in the Azure Functions documentation](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local).
- Install the `DurableTask` extension:
```
func extensions install --package Microsoft.Azure.WebJobs.Extensions.DurableTask -v 2.3.1
```
- Copy the `local.settings.template.json` file and rename to `local.settings.json`, and configure the `AzureWebJobsStorage` value to be a valid storage connection string. [See the documentation for more info](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local#local-settings-file)## Quick Start
1. Run `npm install` to install the required dependencies.
1. Hit F5 or run `npm start` to start the function.## Interacting with the State Machine
In this sample, the `DonutEntity` is controlled by the following statechart:
[View this statechart on XState Viz](https://xstate.js.org/viz/?gist=529435f997b4276799778db37f64b0da)
**To send an event to an entity:**
Open up an API client, such as [Postman](https://postman.com), and `POST` a JSON event object, which is an object that contains a `{ type: "someEventType" }` property, to `http://localhost:7071/api/DonutTrigger?id=`:
```
POST http://localhost:7071/api/DonutTrigger?id=donut1{
"type": "NEXT"
}
```Or using `curl`:
```bash
curl -d '{"type": "NEXT"}' -H "Content-Type: application/json" -X POST http://localhost:7071/api/DonutTrigger?id=donut1
```The text response should be similar to:
> `Event "NEXT" sent to entity "donut1".`
**To view the state of an entity:**
In the same API client, send a `GET` request to `http://localhost:7071/api/DonutTrigger?id=`
```
GET http://localhost:7071/api/DonutTrigger?id=donut1
```Or using `curl`:
```bash
curl http://localhost:7071/api/DonutTrigger?id=donut1
```Example response:
```json
{
"entityExists": true,
"entityState": {
...
"value": {
"directions": "makeDough"
},
...
"event": {
"type": "NEXT"
},
...
}
}
```