2.1.0 • Published 10 months ago

@xstate/fsm v2.1.0

Weekly downloads
67,280
License
MIT
Repository
github
Last release
10 months ago

@xstate/fsm

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

Features

@xstate/fsmXState
Finite states
Initial state
Transitions (object)
Transitions (string target)
Delayed transitions
Eventless 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, { type: 'TOGGLE' });
toggledState.value;
const untoggledState = toggleMachine.transition(toggledState, {
  type: '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({ type: 'TOGGLE' });
toggleService.send({ type: 'TOGGLE' });
toggleService.stop();
@rcanalytics/checkbox@rcanalytics/tablefj-web-playerrecord-the-webrrweb-zipy2rrweb-zipy3rrweb-zp0rrweb-version-2rrweb-z-v2rrweb-z-v4rrweb-z0rrweb-new-vv4-rrwebv3-rrweb@demostack/rrweb@infinitebrahmanuniverse/nolb-_xsedocu-sdk@everything-registry/sub-chunk-1033test-rrwebnode-red-contrib-modbus-temponode-red-contrib-modbusnode-red-contrib-iiot-opcuanode-red-contrib-eflex-modbusnuxt-xstateposthog-rrwebng112-jsmyel-clientmrrwebnavh-metamask-snaps-controllers@deploysentinel/rrweb@corejam/plugin-dershop@cktech/rrweb@dotdev-joel/hydrogen-reactcaf_fsm@dcdn/data-transfer@dashboarding/rrwebchenghong-rrweb-1@tutorio/rrwebzipy-rrwebzipy-rrweb-qazipy-rrweb-replayerzipy-rrweb-testzipy-test-rrwebasync-data-hooksaudio-react@atlasinc/rrweb@bitpool-edge/node-red-contrib-bitpool-modbus@bitpoolos/edge-modbus@bss-sbc/rrweb@blinq-reach/machineapollo-client-devtoolsxsolla-uikit@airsoko/react@amplitude/rrweb@troglotit/rrwebcode-theme-converterfluent-machineflux-machine@wechange/frontend-corekoreaats-lib-io-v1react-next-formremote-instructionrobo-wizardredux-statechartrrweb-salespolicyrrweb-zipy1rrwebrrweb-customrrweb-new-versionrrweb-nv2rrweb-qtskygram-sdk-dev@luminai-platform/rrwebsvelte-helpersstorytimestorytime-appvideocommvcomrtc-re2web@xysfe/memento-core@uspk-ui/react-listboxwr-rrweb@juice10/rrweb@koreaats/lib-io-v1@livecycle.io/rrweb@ideal-postcodes/address-finderglutton-recorder@metamask/snaps-controllers@metamask/snap-controllers@ncstat/parser@mjsz-vbr-elements/core@kenke7/node-red-contrib-modbus@importable/machine@happykit/auth@happykit/auth-emailconcurrently.macro@highlight-run/rrweb@rrweb/profile-rrweb@reach/machine@reach-ui-fork/machineideacome-rrweb
3.0.0-beta.3

10 months ago

2.1.0

10 months ago

2.0.1

11 months ago

3.0.0-beta.2

1 year ago

3.0.0-alpha.1

1 year ago

3.0.0-alpha.0

1 year ago

2.0.0

2 years ago

1.6.4

2 years ago

1.6.3

2 years ago

1.6.5

2 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.2

3 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago