All Projects → mattpocock → Xstate Codegen

mattpocock / Xstate Codegen

Licence: mit
A codegen tool for 100% TS type-safety in XState

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Xstate Codegen

Xcassetpacker
A command line tool for converting a folder of images into an .xcasset package for Xcode
Stars: ✭ 150 (-5.06%)
Mutual labels:  cli, codegen
Fselect
Find files with SQL-like queries
Stars: ✭ 3,103 (+1863.92%)
Mutual labels:  cli
Actions Cli
Monitor your GitHub Actions in real time from the command line
Stars: ✭ 156 (-1.27%)
Mutual labels:  cli
Gh
Easily manage your local git repos
Stars: ✭ 156 (-1.27%)
Mutual labels:  cli
Proji
A powerful cross-platform CLI project templating tool.
Stars: ✭ 156 (-1.27%)
Mutual labels:  cli
Slack Cli
Slack CLI for productive developers
Stars: ✭ 157 (-0.63%)
Mutual labels:  cli
Drone Ssh
Drone plugin for executing remote ssh commands
Stars: ✭ 155 (-1.9%)
Mutual labels:  cli
Passw0rd
🔑securely checks a password to see if it has been previously exposed in a data breach
Stars: ✭ 159 (+0.63%)
Mutual labels:  cli
Python Pushover
Comprehensive bindings and command line utility for the Pushover notification service
Stars: ✭ 158 (+0%)
Mutual labels:  cli
Licenseplist
A license list generator of all your dependencies for iOS applications
Stars: ✭ 1,996 (+1163.29%)
Mutual labels:  cli
C
Compile and execute C "scripts" in one go!
Stars: ✭ 1,920 (+1115.19%)
Mutual labels:  cli
Packtpub Downloader
Script to download all your books from PacktPub inspired by https://github.com/ozzieperez/packtpub-library-downloader
Stars: ✭ 156 (-1.27%)
Mutual labels:  cli
Gitoxide
An idiomatic, lean, fast & safe pure Rust implementation of Git
Stars: ✭ 2,696 (+1606.33%)
Mutual labels:  cli
Gif Progress
🎬 Attach progress bar to animated GIF
Stars: ✭ 156 (-1.27%)
Mutual labels:  cli
Enhancd
🚀 A next-generation cd command with your interactive filter
Stars: ✭ 2,049 (+1196.84%)
Mutual labels:  cli
Abandon
😌 Simple and Robust Accounting
Stars: ✭ 155 (-1.9%)
Mutual labels:  cli
Texture Compressor
CLI tool for texture compression using ASTC, ETC, PVRTC and S3TC in a KTX container.
Stars: ✭ 156 (-1.27%)
Mutual labels:  cli
Foy
A simple, light-weight and modern task runner for general purpose.
Stars: ✭ 157 (-0.63%)
Mutual labels:  cli
Eslint Watch
ESLint with simple watching capabilities
Stars: ✭ 159 (+0.63%)
Mutual labels:  cli
Uptoc
A static file deployment tool that supports multiple platforms./ 一个支持多家云厂商的静态文件部署工具
Stars: ✭ 159 (+0.63%)
Mutual labels:  cli

Type Safe State Machines

xstate-codegen gives you 100% type-safe usage of XState in Typescript. Try it out at this codesandbox!

You get type safety on:

  • Transition targets: on: {EVENT: 'deep.nested.state'}
  • Services
  • Guards
  • Activities
  • Actions
  • The initial attribute
  • state.matches('deep.nested.state')

This works by introspecting your machine in situ in your code. With this Thanos-level power, we can click our fingers and give you 100% type safety in your state machines.

Usage

CLI

xstate-codegen "src/**/**.machine.ts"

Inside code

Instead of importing createMachine or Machine from xstate, import them from @xstate/compiled:

import { createMachine } from '@xstate/compiled';

const machine = createMachine();

You must pass three type options to createMachine/Machine:

  1. The desired shape of your machine's context
  2. The list of events your machine accepts, typed in a discriminated union (type Event = { type: 'GO' } | { type: 'STOP' };)
  3. A string ID for your machine, unique to your project.

For instance:

import { Machine } from '@xstate/compiled';

interface Context {}

type Event = { type: 'DUMMY_TYPE' };

const machine = Machine<Context, Event, 'uniqueId'>({});

Usage with React

import { useMachine } from '@xstate/compiled/react';
import { machine } from './myMachine.machine'

const [state, dispatch] = useMachine(machine, {
  // all options in here will be type checked
})

Usage with Interpret

import { interpret } from '@xstate/compiled';
import { machine } from './myMachine.machine'

const service = interpret(machine, {
  // all options in here will be type checked
})

Options

Once

xstate-codegen "src/**/**.machine.ts" --once

By default, the CLI watches for changes in your files. Running --once runs the CLI only once.

Out Dir

xstate-codegen "src/**/**.machine.ts" --outDir="src"

By default, the CLI adds the required declaration files inside node_modules at node_modules/@xstate/compiled. This writes the declaration files to a specified directory.

Note, this only writes the declaration files to the directory. The .js files still get written to node_modules/@xstate/compiled.

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