2.1.0 • Published 1 year ago

@xstate/fsm v2.1.0

Weekly downloads
67,280
License
MIT
Repository
github
Last release
1 year 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-_xs@everything-registry/sub-chunk-1033test-rrwebsvelte-helperswr-rrwebremote-instructionrobo-wizardstorytimestorytime-appvcomrtc-re2webvideocomm@wechange/frontend-corehydrogen-react-devmrrwebkoreaats-lib-io-v1highlight-rrwebhubble-recordhubble-rrwebhowdygo-rrwebideacome-rrwebjose-streamglutton-recordermyel-clientnavh-metamask-snaps-controllersposthog-rrwebng112-jsnode-red-contrib-iiot-opcuanode-red-contrib-eflex-modbusnode-red-contrib-modbusnode-red-contrib-modbus-flex-servernode-red-contrib-modbus-temporeact-next-formnuxt-xstatenuxt-xstate5redux-statechartrrwebrrweb-customrrweb-new-versionrrweb-nv2rrweb-qtrrweb-salespolicyrrweb-zipy1skygram-sdk-dev@amplitude/rrweb@atlasinc/rrweb@airsoko/react@bitpool-edge/node-red-contrib-bitpool-modbus@bitpoolos/edge-modbus@bss-sbc/rrweb@cktech/rrweb@dcdn/data-transfer@dashboarding/rrwebxsolla-uikitzipy-test-rrwebzipy-rrwebzipy-rrweb-qazipy-rrweb-replayerzipy-rrweb-test@ficusjs/state@happykit/auth@happykit/auth-email@flywheelapp/rrweb@highlight-run/rrweb@ideal-postcodes/address-finder@koreaats/lib-io-v1@livecycle.io/rrweb@luminai-platform/rrweb@ncstat/parser@metamask/snap-controllers@metamask/snaps-controllers@mjsz-vbr-elements/core@importable/machine@juice10/rrweb@kenke7/node-red-contrib-modbus@reach/machine@reach-ui-fork/machine@samuelberthe/rrweb@saola.ai/rrweb@screeb/rrweb@smartesting/rrweb@shopify/hydrogen-react@surecart/components@swer/rrweb@shopify/storefront-kit-react@sentry-internal/rrweb
3.0.0-beta.3

1 year ago

2.1.0

1 year ago

2.0.1

2 years ago

3.0.0-beta.2

2 years ago

3.0.0-alpha.1

2 years ago

3.0.0-alpha.0

2 years ago

2.0.0

3 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.5

3 years ago

1.6.2

3 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.3.0

5 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago