@xstate/fsm
XState for finite state machines

@xstate/fsm downloads @xstate/fsm version @xstate/fsm license

@xstate/fsm유사 패키지:
npm 다운로드 트렌드
3 년
🌟 @xstate/fsm의 README.md에 실시간 사용 차트를 표시하려면 아래 코드를 복사하세요.
## Usage Trend
[![Usage Trend of @xstate/fsm](https://npm-compare.com/img/npm-trend/THREE_YEARS/@xstate/fsm.png)](https://npm-compare.com/@xstate/fsm#timeRange=THREE_YEARS)
Cumulative GitHub Star Trend
🌟 @xstate/fsm의 README.md에 GitHub Stars 트렌드 차트를 표시하려면 아래 코드를 복사하세요.
## GitHub Stars Trend
[![GitHub Stars Trend of @xstate/fsm](https://npm-compare.com/img/github-trend/@xstate/fsm.png)](https://npm-compare.com/@xstate/fsm)
통계 세부사항
패키지
다운로드
Stars
크기
Issues
발행일
라이선스
@xstate/fsm1,730,24528,85857.1 kB1682年前MIT
@xstate/fsm의 README

@xstate/fsm


XState FSM
XState for Finite State Machines

This package contains a minimal, 1kb implementation of XState for finite state machines.

Features

| | @xstate/fsm | XState | | --------------------------- | :-------------: | :-------------------------------------------: | | Finite states | ✅ | ✅ | | Initial state | ✅ | ✅ | | Transitions (object) | ✅ | ✅ | | Transitions (string target) | ✅ | ✅ | | Delayed transitions | ❌ | ✅ | | Eventless transitions | ❌ | ✅ | | Wildcard transitions | ✅ | ✅ | | Nested states | ❌ | ✅ | | Parallel states | ❌ | ✅ | | History states | ❌ | ✅ | | Final states | ❌ | ✅ | | Context | ✅ | ✅ | | Entry actions | ✅ | ✅ | | Exit actions | ✅ | ✅ | | Transition actions | ✅ | ✅ | | Parameterized actions | ❌ | ✅ | | Transition guards | ✅ | ✅ | | Parameterized guards | ❌ | ✅ | | Spawned actors | ❌ | ✅ | | Invoked actors | ❌ | ✅ |

  • Finite states (non-nested)
  • Initial state
  • Transitions (object or strings)
  • Context
  • Entry actions
  • Exit actions
  • Transition actions
  • state.changed

If you want to use statechart features such as nested states, parallel states, history states, activities, invoked services, delayed transitions, transient transitions, etc. please use XState.

Quick start

Installation

npm i @xstate/fsm

Usage (machine)

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

const toggleMachine = createMachine({
  id: 'toggle',
  initial: 'inactive',
  states: {
    inactive: { on: { TOGGLE: 'active' } },
    active: { on: { TOGGLE: 'inactive' } }
  }
});

const { initialState } = toggleMachine;

const toggledState = toggleMachine.transition(initialState, 'TOGGLE');
toggledState.value;
const untoggledState = toggleMachine.transition(toggledState, 'TOGGLE');
untoggledState.value;
// => 'inactive'

Usage (service)

import { createMachine, interpret } from '@xstate/fsm';

const toggleMachine = createMachine({});

const toggleService = interpret(toggleMachine).start();

toggleService.subscribe((state) => {
  console.log(state.value);
});

toggleService.send('TOGGLE');
toggleService.send('TOGGLE');
toggleService.stop();