Giter Club home page Giter Club logo

state-designer's Introduction

State Designer

โš ๏ธ This project is not yet fully documented. The best way to explore the project is through its tutorials package.

State Designer is a JavaScript and TypeScript library for managing the state of a user interface. It prioritizes the design experience, making it easy to experiment with ideas, iterate on solutions, and communicate the final result.

Learn more at state-designer.com.

Features

  • Create your state using a flexible, declarative syntax.
  • Use collections to reuse code and clarify make your state.
  • Create both global and local states.

Packages

Starters

Usage

Using State Designer involves three steps:

  1. Create a state with a configuration object.
  2. Subscribe to the state's updates.
  3. Send events to the state.

Your exact usage will depend on your framework:

Example

Note: This example uses the React package.

Edit little-snowflake-rmu8q

import React from "react"
import { useStateDesigner } from "@state-designer/react"

function App() {
  const { data, send, can, whenIn } = useStateDesigner({
    data: { count: 1 },
    initial: "inactive",
    states: {
      inactive: {
        on: { TOGGLED: { to: "active" } },
      },
      active: {
        on: {
          TOGGLED: { to: "inactive" },
          CLICKED_PLUS: { if: "belowMax", do: "increment" },
          CLICKED_MINUS: "decrement",
        },
      },
    },
    actions: {
      increment(d) {
        d.count++
      },
      decrement(d) {
        d.count--
      },
    },
    conditions: {
      belowMax(d) {
        return d.count < 10
      },
    },
  })

  return (
    <div className="App">
      <h2>{data.count}</h2>
      <button
        disabled={!can("CLICKED_MINUS")}
        onClick={() => send("CLICKED_MINUS")}
      >
        -1
      </button>
      <button
        disabled={!can("CLICKED_PLUS")}
        onClick={() => send("CLICKED_PLUS")}
      >
        +1
      </button>
      <button onClick={() => send("TOGGLED")}>
        {whenIn({
          active: "Turn Off",
          inactive: "Turn On",
        })}
      </button>
    </div>
  )
}

export default App

Inspiration

State Designer is heavily inspired by xstate. Note that, unlike xstate, State Designer does not adhere to the scxml spec.

Author

License

MIT

state-designer's People

Contributors

dependabot[bot] avatar steveruizok avatar

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.