Actyx / Actyx/machines

[Brain Dump] Event-As-Destination-State

Đang mở
#66 7 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement wontfix
Ngôn ngữ chính
TypeScript
Star
8
Fork
2
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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)
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.