From 880bed17efd8d1607022d5d31c6e76911c162adf Mon Sep 17 00:00:00 2001 From: Brian Zinn Date: Sat, 20 Feb 2021 14:27:24 -0800 Subject: [PATCH] chore: add release notes --- .npmignore | 6 ++++++ README.md | 28 ++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 35 insertions(+) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..84a2479 --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +src +test +tsconfig.json +tsconfig.test.json +tslint.json +README.md \ No newline at end of file diff --git a/README.md b/README.md index 452dd03..b968ebf 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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.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 \ No newline at end of file diff --git a/package.json b/package.json index 375fcb1..6b1c7e2 100644 --- a/package.json +++ b/package.json @@ -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",