Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/appsweet-co/stately-machine
A Finite State Machine using Observables
https://github.com/appsweet-co/stately-machine
finite-state-machine npm npm-module npm-package reactive-programming rxjs typescript
Last synced: about 1 month ago
JSON representation
A Finite State Machine using Observables
- Host: GitHub
- URL: https://github.com/appsweet-co/stately-machine
- Owner: Appsweet-co
- License: mit
- Created: 2022-12-10T02:26:28.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-10T17:58:17.000Z (over 1 year ago)
- Last Synced: 2024-12-13T05:11:59.256Z (2 months ago)
- Topics: finite-state-machine, npm, npm-module, npm-package, reactive-programming, rxjs, typescript
- Language: TypeScript
- Homepage: https://appsweet-co.github.io/stately-machine
- Size: 183 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
Stately Machine
A Finite State Machine using Observables
## Playground
See [Stackblitz](https://stackblitz.com/edit/stately-machine?devtoolsheight=100&file=index.ts) for an interactive demo.
## API Docs
See our [documentation website](https://appsweet-co.github.io/stately-machine/) for API docs.
## Error Types
See our [API Docs](https://appsweet-co.github.io/stately-machine/types/StatelyErrorType.html) for details on all errors.
## Quick Start
Install using npm.
```zsh
npm i @appsweet-co/stately-machine
```Import the class directly into your code.
```ts
import { StatelyMachine } from "@appsweet-co/stately-machine";
```See [Stackblitz](https://stackblitz.com/edit/stately-machine?devtoolsheight=100&file=index.ts) for details on how to set up a new machine.
## More Info
Stately Machine is a Finite State Machine for TypeScript. It uses [Observables](https://rxjs.dev/) instead of callbacks to manage state events.
Use an Enum to [store states](https://stackblitz.com/edit/stately-machine?devtoolsheight=100&file=index.ts:L13-L18). We recommend [String Enums](https://www.typescriptlang.org/docs/handbook/enums.html#string-enums) for easy iteration using [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values).
You can also set an [optional context](https://stackblitz.com/edit/stately-machine?devtoolsheight=100&file=index.ts:L22-L27) made of any key-value pairs you need. Update and access the context as needed.
Stately Machine makes no assumptions about what you want to do when an error happens. You must subscribe to the [error observables](https://stackblitz.com/edit/stately-machine?devtoolsheight=100&file=index.ts:L47-L51) to get details about each error.
Stately Machine also makes no assumptions about what you want to do for a successful change in state. You must subscribe to the [success observables](https://stackblitz.com/edit/stately-machine?devtoolsheight=100&file=index.ts:L57-L61) to get details about each state change.