Giter Club home page Giter Club logo

xstate.dart's Introduction

xstate.dart pub package Dart CI

WIP xstate for dart & flutter

Example

CD Player:

final machine = Machine.fromJson({
  "key": "cd",
  "initial": "not_loaded",
  "states": {
    "not_loaded": {
      "on": {"INSERT_CD": "loaded"}
    },
    "loaded": {
      "initial": "stopped",
      "on": {"EJECT": "not_loaded"},
      "states": {
        "stopped": {
          "on": {"PLAY": "playing"}
        },
        "playing": {
          "on": {
            "STOP": "stopped",
            "EXPIRED_END": "stopped",
            "EXPIRED_MID": "playing",
            "PAUSE": "paused"
          }
        },
        "paused": {
          "initial": "not_blank",
          "states": {
            "blank": {
              "on": {"TIMER": "not_blank"}
            },
            "not_blank": {
              "on": {"TIMER": "blank"}
            }
          },
          "on": {"PAUSE": "playing", "PLAY": "playing", "STOP": "stopped"}
        }
      }
    }
  }
});

machine.start(); // not_loaded
machine.transition('not_loaded', 'INSERT_CD'); // loaded.stopped
machine.transition('loaded.paused', 'EJECT'); // not_loaded

Roadmap & Features

Core
  • Core FSM and functions. machine.start() , machine.transition(current, event) & state.matches('state')
  • Basic support for Hierarchical or Nested State Machines. State(child: Machine ...
  • Complete implementation of Statecharts (guards, context, ...)
  • Parallel State Machines
  • History States
  • Refrence by id. State(on: {"2": '#B'})
  • Machine.fromJson({}) ability to create machines with JSON Schema
  • Machine.fromSCXML('<></>') ability to create machines with SCXML
  • Binding package for flutter
  • Binding package for flutter_hook
  • Utility package for writing tests
  • More tests
Tooling
  • Run a webserver in watch mode and show all the machines in xstatejs's visualizer
Dart Analyzer Plugin
  • Show outline for a machine and its states

image

  • [Quick Fix] Convert Machine.fromJson({}) & Machine.fromSCXML('<></>') to Machine()
  • [Quick Fix] Convert Machine() to Machine.fromJson({}) or Machine.fromSCXML('<></>')
  • [Diagnostic] machine.maches('state.state_that_doesnt_exists') validation. (throw state_that_doesnt_exists doesn't exists on the machine)
  • [Diagnostic] Provide warning and errors when creating a machine for invalid transition, invalid paths and unused event and states.
  • [Quick Fix] Extract nested machines.

xstate.dart's People

Contributors

sahandevs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xstate.dart's Issues

Feature Request/Suggestion

Unlike TypeScript, Dart can't simply apply an Interface to incoming data, like JSON, and have it "just work." (Which is a huge bummer, and makes functional programming harder)

Because of this and other language design choices, handling async data and requests, especially multiple requests, with xstate in dart, will be more difficult than it already is in TypeScript.

Packages like built_value, and built_collection, come with json serialization built in.

They also have a lot of other features that would be great if inherited by xstate.

I'm asking if there is a way to link xstate with these two other packages, and use code_gen to do so?

If xstate wants to widely be used in Dart, code generation may be necessary, and json serialization should be made as easy as possible.

mobx makes use of code_gen to make development super easy.

There are lots of benefits to using code_gen, built_value, and built_collection in projects, so I thought I'd suggest them.

Let me know if you'd need help of are excepting pull requests.

Any updates for 2022?

Hello,
It looks like this project has be quiet for 2 years. Any plans to restart work in 2022?

[WIP] Implementation Plan

Machine Definition

Defining https://www.w3.org/2011/04/SCXML/scxml.xsd with dart models.

Translation

image
Convert a machine that user provides to the machine definition format.

  • machine.fromJson : xstatejs format
  • machine.fromSCXML: scxml format

Interpreter

image

An interpreter takes one Machine Definition (required), one Initial State and zero or more hooks and returns a Machine Instance.

Hooks

hook to an internal event of the interpreter. (onRaiseError, onStateChanged, ... )

Machine Instance

provides these properties:

  • Stream<State> state: current state of the machine
    • State :
      • value: current state value
      • matches(State pattern): check if the state matches a pattern
      • context
  • void send(Event event): sends event to the machine

Flutter

  • Basic binding for flutter
  • Provide a simple example

Basic Tooling

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.