stepanvanzuriak / Finite
Licence: mit
UI as finite-state machine
Stars: ✭ 99
Programming Languages
javascript
184084 projects - #8 most used programming language
typescript
32286 projects
Labels
Projects that are alternatives of or similar to Finite
River Admin
🚀 A shiny admin interface for django-river built with DRF, Vue & Vuetify
Stars: ✭ 55 (-44.44%)
Mutual labels: state-machine
Pylstar
An implementation of the LSTAR Grammatical Inference Algorithm
Stars: ✭ 41 (-58.59%)
Mutual labels: state-machine
React Context Hook
A React.js global state manager with Hooks
Stars: ✭ 50 (-49.49%)
Mutual labels: state-machine
State Machine
🤖 A state machine library for Kotlin, with extensions for Android.
Stars: ✭ 72 (-27.27%)
Mutual labels: state-machine
Makina
A simple hierarchical state machine compiler that generates C.
Stars: ✭ 93 (-6.06%)
Mutual labels: state-machine
Aws Power Tuner Ui
AWS Lambda Power Tuner UI is an open source project creating a deployable easy to use website built on a layered technology stack allowing you to optimize your Lambda functions for cost and/or performance in a data-driven way via an easy to use UI.
Stars: ✭ 52 (-47.47%)
Mutual labels: state-machine
Formatwith
String extensions for named parameterized string formatting.
Stars: ✭ 44 (-55.56%)
Mutual labels: state-machine
Xstateful
A wrapper for xstate that stores state, handles transitions, emits events for state changes and actions/activities, and includes an optional reducer framework for updating state and invoking side-effects
Stars: ✭ 81 (-18.18%)
Mutual labels: state-machine
Finity
A finite state machine library for Node.js and the browser with a friendly configuration DSL.
Stars: ✭ 88 (-11.11%)
Mutual labels: state-machine
Mineflayer Statemachine
A state machine plugin for Mineflayer to aid in designing more complex behavior trees.
Stars: ✭ 32 (-67.68%)
Mutual labels: state-machine
Hal
🔴 A non-deterministic finite-state machine for Android & JVM that won't let you down
Stars: ✭ 63 (-36.36%)
Mutual labels: state-machine
Workflow Swift
A Swift and Kotlin library for making composable state machines, and UIs driven by those state machines.
Stars: ✭ 92 (-7.07%)
Mutual labels: state-machine
React Automata
A state machine abstraction for React
Stars: ✭ 1,316 (+1229.29%)
Mutual labels: state-machine
🤔 Why?
User interfaces can be expressed by two things:
- The state of the UI
- Actions that can change that state
And we can connect this two points with Finite-state machine. This simple micro framework use State as main part of web page.
💻 Install and Usage
Install finite using your package manager
$ npm install @stepanvanzuriak/finite
And just use!
import Finite, { State, h } from "@stepanvanzuriak/finite";
const JustText = State({
view: () => h`<p>Hello!</p>`
});
Finite.Render(JustText, document.body);
Simple counter example
const Counter = Finite.State({
name: "counter",
transitions: [
Finite.T("INCREMENT", "counter"),
Finite.T("DECREMENT", "counter")
],
memory: { count: 0 },
increment: (_, { count }) =>
Finite.Transition("INCREMENT", { count: count + 1 }),
decrement: (_, { count }) =>
Finite.Transition("INCREMENT", { count: count - 1 }),
view: ({ count, increment, decrement }) =>
h`<div class="app">
<button onclick=${decrement}>-1</button>
<div>${count}</div>
<button onclick=${increment}>+1</button>
</div>`
});
Finite.Render(Counter, document.body);
Two state example
const A = Finite.State({
name: "A",
memory: {
text: "Text A"
},
transitions: [Finite.T("MOVE_TO_B", "B")],
onClick: e => Finite.Transition("MOVE_TO_B"),
view: ({ text, onClick }) =>
h`<div class="app">
<div>${text}</div><button onclick=${onClick}>To B</button>
</div>`
});
const B = Finite.State({
name: "B",
memory: {
text: "Text B"
},
transitions: [Finite.T("MOVE_TO_A", "A")],
onClick: e => Finite.Transition("MOVE_TO_A", { text: "New Text A" }),
view: ({ text, onClick }) =>
h`<div class="app">
<div>${text}</div><button onclick=${onClick}>To A</button>
</div>`
});
Finite.Render(A, document.body);
example
folder
More examples in 📝 TODO
- [x] Write own html template (instead of lit-html) to reduce bundle size. See picohtml
- [ ] Create Finite.State version as ES6 class
- [ ] Rethink AsyncTransition (Promise rejection)
- [ ] Move examples to CodeSandbox
- [ ] Better tests
📖 Api
State
Finite.State({
view,
[name],
[memory],
[transitions],
[...rest]
}: IStateType)
You can use rest
for own methods like onChange, onClick
etc.
Transition
Finite.Transition(
name : String,
[payload] : Object
)
Change current state to another, name
is name from state transitions and payload
is extra data to send
AsyncTransition
Finite.Transition(
name : String,
[payload] : Object
)
Instead of normal Transition
you can set data in payload as Promise
and Finite
will change state only when data become fetched.
See async.js
in example
folder
Render
Finite.Render(
state: State,
point: HTMLElement
)
Set render point and init state for app
T
Finite.T(
name: String,
to: String
) -> {name, to}
🖊️ Typings
interface ITransition {
name: string;
to: string;
}
interface IStateType {
view: (...args) => any;
name: string;
memory: object;
transitions: ITransition[];
rest: object;
}
💁 Contribute
If you want to contribute to this project, please see our Contributing Guide !
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].