Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/barteh/machinize
a javascript library implements finite-state machine for application developement purpose
https://github.com/barteh/machinize
barteh bornamehrfann finite-state-machine fsm javascript library machinize rafat
Last synced: about 1 month ago
JSON representation
a javascript library implements finite-state machine for application developement purpose
- Host: GitHub
- URL: https://github.com/barteh/machinize
- Owner: barteh
- License: mit
- Created: 2018-07-10T16:06:04.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T15:16:16.000Z (about 2 years ago)
- Last Synced: 2025-01-01T17:28:35.359Z (about 1 month ago)
- Topics: barteh, bornamehrfann, finite-state-machine, fsm, javascript, library, machinize, rafat
- Language: JavaScript
- Size: 347 KB
- Stars: 10
- Watchers: 5
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/barteh/machinize.svg?branch=master)](https://travis-ci.org/barteh/machinize)
# Machinize
## a javascript library implements finite-state machine for application developement purpose## main features
- change objects to machine automaticly.
- define machine behavior once and create many instances.
- automatic transitions with defined condition.
- supports parametric observable (source state, destinition state or both) observable state changes based on rxjs.
- supports blockable hooks contain(befor, after Enter and exit) from or to states.
- data included access via `this` .
- define auto transition by a condition.
- imutable state.
- actions that acces to `this` so data and parameters.
- supports computed data .
- many usefull features will be document soon![](https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Finite_state_machine_example_with_comments.svg/420px-Finite_state_machine_example_with_comments.svg.png)
---
### install
```
npm i @barteh/machinize
```
---
### usage
```js
import Machinize from "@barteh/machinize"
const machine = Machinize.init({
name: "myMachine",
data: {
light: 55 // of 100
},states: {
"off": {
description: "light is off"},
"on": {
description: "light is on",
onEnter() { // auto off after 2s
// setTimeout(() => {
// if (this.light < 60)
// this.switchoff();
// }, 1000);
}
}
},
transitions: {
"switchon": {
from: "off",
to: "on"
},
"switchoff": {
from: "on",
to: "off",
entryCondition(){
return this.light<55;
}
}},
actions: {
do_on() {
this.switchon();
}
}});
const machinInstance = machine.createInstance({light: 31});
machinInstance
.$observable()
.subscribe(a => {
console.log( a.message)
})machinInstance.do_on(); // light is on
setTimeout(() => {
machinInstance.light=44; //light is off
}, 2000);```
---
### test
```
npm run test
```
---
### build```
npm run build
```License: MIT
2017