Skip to content

Commit

Permalink
documentation updated
Browse files Browse the repository at this point in the history
  • Loading branch information
shuvalov-mdb committed Oct 29, 2020
1 parent 133ae88 commit 28b0d33
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# C++ State Machine generator for Xstate

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

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

## Install and Quick Start Tutorial

Install the xstate-cpp-generator TypeScript package, locally (or globally with `-g` option):

```bash
npm install xstate-cpp-generator
```
Create a simple Xstate model file `ping.ts` with few lines to trigger C++ generation at the end:

```TypeScript
const CppGen = require('xstate-cpp-generator');
const path = require('path');

import { Machine, createMachine, assign } from 'xstate';

const pingPongMachine = Machine({
id: 'ping',
initial: 'init',
states: {
init: {
on: {
'START': { target: 'pinging', actions: ['savePongActorAddress', 'spawnPongActor'] }
}
},
pinging: {
onEntry: 'sendPingToPongActor',
on: {
'PONG': { target: 'pinging', actions: ['sendPingToPongActor']}
}
}
}
});


CppGen.generateCpp({
xstateMachine: pingPongMachine,
destinationPath: "",
namespace: "mongo",
pathForIncludes: "example-ping-pong",
tsScriptName: path.basename(__filename)
});
```

And generate C++ with:

```bash
ts-node ping.ts
```
You should see new generated files:
```
ping_sm.cpp ping_sm.h ping_test.cpp
```

0 comments on commit 28b0d33

Please sign in to comment.