Skip to content

Commit

Permalink
chore: add release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
brianzinn committed Feb 20, 2021
1 parent ba980b5 commit 880bed1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
src
test
tsconfig.json
tsconfig.test.json
tslint.json
README.md
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# xmachina
Simple Typesafe State Machine.

name inspired from the movie ex-machina.

Just a simple state machine that allows working with a typesafe state machine. Although you can use strings to represent states, also allows numbers/enums.

Has a fluent API for building state machines or you can create you own with a Map.
Expand All @@ -10,5 +12,31 @@ To include in your project:
yarn add xmachina
```

| Create a lightswitch that starts out on - turn it off.
```typescript
enum LightState {
On,
Off
};

const machina = createMachina<LightState, Transition<LightState>>(LightState.On)
.addState(LightState.On, {
name: 'off',
nextState: LightState.Off,
description: 'turn off light switch'
})
.addState(LightState.Off, {
name: 'on',
nextState: LightState.On,
description: 'turn on light switch'
})
.build();

assert.strictEqual(LightState.On, machina.state.current);
assert.deepStrictEqual(['off'], machina.state.possibleTransitions.map(t => t.name));

const newState = machina.transitionTo('off');
```

## TODO:
* add observables
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@types/mocha": "^8.2.1",
"@types/node": "^14.14.31",
"cross-env": "^7.0.3",
"github-release-notes": "^0.17.3",
"mocha": "^8.3.0",
"nyc": "^15.1.0",
"ts-node": "^9.1.1",
Expand Down

0 comments on commit 880bed1

Please sign in to comment.