All Projects → kristianmandrup → bs-xstate

kristianmandrup / bs-xstate

Licence: other
Bucklescript bindings for XState state machine

Programming Languages

ocaml
1615 projects

bs-xstate

Bucklescript bindings for xstate.

State machines and statecharts for the modern web.

Use

Install

npm i bs-xstate

Add bs-xstate in dependencies of bsconfig.json

Usage

// Stateless machine definition
// machine.transition(...) is a pure function used by the interpreter.
let toggleMachine = XState.machine({
  initial: "inactive",
  states: {
    inactive: { on: { TOGGLE: "active" } },
    active: { on: { TOGGLE: "inactive" } }
  }
});

// Machine instance with internal state
let toggleService = XState.interpret(toggleMachine)
  .onTransition(state => console.log(state.value))
  .start();
// => 'inactive'

toggleService.send("TOGGLE");
// => 'active'

toggleService.send("TOGGLE");
// => 'inactive'

Resources

  • xstate plantuml Visualize a xstate or react-automata statechart as a plantuml state diagram.

Build

npm run build

Watch

npm run watch

Editor

If you use vscode, Press Windows + Shift + B it will build automatically

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].