Skip to content

Commit 28b0d33

Browse files
committed
documentation updated
1 parent 133ae88 commit 28b0d33

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

README.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# C++ State Machine generator for Xstate
22

3-
This package allows to convert TypeScript language State Machine develped
3+
This package allows to convert TypeScript language State Machine developed
44
using [Xstate](https://github.com/davidkpiano/xstate) into C++ generated SM, no coding required.
55

66
Project location: https://github.com/shuvalov-mdb/xstate-cpp-generator
@@ -18,3 +18,55 @@ Copyright Andrew Shuvalov, MIT [License](https://github.com/shuvalov-mdb/xstate-
1818
* Arbitrary user-defined data structure (called Context) can be stored in the SM
1919
* Any event can have an arbitrary user-defined payload attached. The event payload is propagated to related callbacks
2020

21+
## Install and Quick Start Tutorial
22+
23+
Install the xstate-cpp-generator TypeScript package, locally (or globally with `-g` option):
24+
25+
```bash
26+
npm install xstate-cpp-generator
27+
```
28+
Create a simple Xstate model file `ping.ts` with few lines to trigger C++ generation at the end:
29+
30+
```TypeScript
31+
const CppGen = require('xstate-cpp-generator');
32+
const path = require('path');
33+
34+
import { Machine, createMachine, assign } from 'xstate';
35+
36+
const pingPongMachine = Machine({
37+
id: 'ping',
38+
initial: 'init',
39+
states: {
40+
init: {
41+
on: {
42+
'START': { target: 'pinging', actions: ['savePongActorAddress', 'spawnPongActor'] }
43+
}
44+
},
45+
pinging: {
46+
onEntry: 'sendPingToPongActor',
47+
on: {
48+
'PONG': { target: 'pinging', actions: ['sendPingToPongActor']}
49+
}
50+
}
51+
}
52+
});
53+
54+
55+
CppGen.generateCpp({
56+
xstateMachine: pingPongMachine,
57+
destinationPath: "",
58+
namespace: "mongo",
59+
pathForIncludes: "example-ping-pong",
60+
tsScriptName: path.basename(__filename)
61+
});
62+
```
63+
64+
And generate C++ with:
65+
66+
```bash
67+
ts-node ping.ts
68+
```
69+
You should see new generated files:
70+
```
71+
ping_sm.cpp ping_sm.h ping_test.cpp
72+
```

0 commit comments

Comments
 (0)