[Brain Dump] Event-As-Destination-State
- Lenguaje dominante
- TypeScript
- Estrellas
- 8
- Forks
- 2
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
In a swarm protocol:
- Transition map one-to-one to a guard event
- Transition map one-to-one to a combination of role, source state, and target state
- There does not seem to be a need for ordered-multi-events transition.
With those properties (and hopefully no need for another compiliation step) swarm protocol and role protocol can be defined this way:
```typescript
const swarmProtocol = Swarm.createProtocol()
.state(["A", "B", "C1", "C2", "D"])
.role("taxi", "passenger")
.transition("passenger", "A", "B").withPayload() // creates event type "passenger-A-to-B"
.transition("taxi", "B", "B").withPayload() // creates event type "taxi-B-to-B" (Loop)
.transition("taxi", "B", "C1").withPayload() // creates event type "taxi-B-to-C1"
.transition("passenger", "B", "C2").withPayload() // creates event type "passenger-B-to-C2"
.transition("passenger", "C1", "D").withPayload() // creates event type "passenger-B-to-C2"
.transition("taxi", "C2", "D").withPayload() // creates event type "taxi-B-to-C2"
.transition("passenger", "C2", "D", (ctx, payload) => ctx.additionalTag(`sometag:${payload.numprop}`)).withPayload() // creates event type "passenger-B-to-C2"
.finish() // builds the swarm protocol complete with the graph
// payload-less machine-runner
// only give payload-less states, but leave commands intact
const machineRunner = createMachineRunner(actyx, tags, swarmProtocol.buildMachineFor("passenger"));
// in default machine
state.commands?.["A-to-B"](theEventPayload);
// custom machines uses old syntax
const taxiMachineProtocol = swarmProtocol.buildMachineCustomRole("taxi");
const A = taxiMachineProtocol
.designState("A")
.withPayload()
.commands("A-to-B", (ctx, value) => [{ ...payloadOfAToB, value }])
.finish()
const B = taxiMachineProtocol
.designState("B")
.withPayload()
.finish()
// custom machines need to be run with `checkProjection`
checkProjection(swarmProtocol, taxiMachineProtocol)
```
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Evaluación
Este issue todavía no se ha evaluado.