1
1
# C++ State Machine generator for Xstate
2
2
3
- This package allows to convert TypeScript language State Machine develped
3
+ This package allows to convert TypeScript language State Machine developed
4
4
using [ Xstate] ( https://github.com/davidkpiano/xstate ) into C++ generated SM, no coding required.
5
5
6
6
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-
18
18
* Arbitrary user-defined data structure (called Context) can be stored in the SM
19
19
* Any event can have an arbitrary user-defined payload attached. The event payload is propagated to related callbacks
20
20
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