1.0.5 ā€¢ Published 3 years ago

state-machine-snacks v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

State Machine Snacks (šŸ•)

A framework built on XState that provides bite sized snacks for developing with state machine machines. šŸ• aims to increase state machine adoption in modern day web apps by providing a suite of tools and plugins to inspire development and new ways of thinking.

šŸ¤ @me on Twitter.

What Is XState?

XState is a library that allows us to create and interpret state machines in JavaScript. It is recommended you understand the basics of XState before using State Machine UI.

šŸš€ Getting Started

For basic usage, šŸ• requires only a XState state machine config as an option. SMS will utilize this config to create a machine and return an XState service.

OptionsDescription
configXState state machine config.Required
createMachineBy default, the machine is created with createMachine(config). You can overwrite this behavior with a function that will be passed the config and must return a XState machine instance.Optional
interpretBy default, the service is interpreted via interpret(machine). You can overwrite this behavior with a function that will be passed both the config and machine instance from the createMachine() step.Optional
pluginsAn array of plugins you want to add to the service.Optional

šŸ• w/Default Settings

import sms from "state-machine-snacks";

const config = { /* ...machine config */ };

// Create your service with šŸ•.
const service = sms({
    config,
});

service.start();

šŸ• w/Advanced Initialization

import sms from "state-machine-snacks";

const config = { /* ...machine config */ };

// Create your service with šŸ• + additional settings.
const service = sms({
    config,

    createMachine : (config) => createMachine(config, { ...actions, ...services }),

    interpret : (config, machine) => interpret(machine).onTransition((state) => {
         console.log(state.value);
    });
});

service.start();

šŸ”Œ Plugins

Plugins add additional functionality to an XState config and service. šŸ• provides a plugin runner and you can add plugins to your state machine by simply adding them to the plugins : [] option when initializing your service.

  • Plugins can export helper functions to be used during plugin usage and state machine composition.
  • Plugins are located in their own repositories prefixed with sms-plugin---. You can find a list of currently available plugins below.
  • Plugins can be passed an object containing options for the plugin.
import sms from "state-machine-snacks";
import components from "sms-plugin---components";
import logger from "sms-plugin---logger";

const config = { /* ...machine config */ };

// Create our state machine with stateUI
const service = sms({
    // Required
    config,

    // Example plugin usage:
    plugins : [
       components(),
       logger(),
    ]
});

service.start();

šŸ“¦ Plugin Components

Conditionally render components as you enter/exit states.

šŸ“¦ Plugin Logger

Provide useful logging when developing with XState.

WIP Plugin Router

Map browser URLs to specific states.

WIP Ethereum Blockchain

Plugin for interacting with the Ethereum blockchain.

WIP Solana Blockchain

Plugin for interacting with the Ethereum blockchain.

WIP Video Call

Plugin for initiating peer to peer video calls via WebRTC + Firebase.

WIP WSIO P2P Chat

Plugin for initiating peer to peer text chats. Firebase?

šŸ’» Examples

āœØ Simple UI

Example of a simple UI utilizing State Machine Snacks and Plugin Components. See how you can use a state machine to render components.

šŸ›  Contribute

Resources

Links to Everything

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago