This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@bemedev/fstate
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

fstate


Fstate for Server/Functions



Features

'@bemedev/fstate'
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(promises only)


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`](https://github.com/statelyai/xstate).


Quick start



Installation


npm i @bemedev/fstate //or
yarn add @bemedev/fstate //or
pnpm add @bemedev/fstate

Usage (machine)


import { createMachine, serve } from '@bemedev/fstate';
const machine = createMachine(
  {
    tsTypes: {
      args: {} as number,
      context: {} as { val: string },
    },
    context: { val: '' },
    initial: 'idle',
    states: {
      idle: {
        type: 'sync',
        transitions: [
          {
            target: 'prom',
          },
        ],
      },
      prom: {
        type: 'async',
        promise: 'prom',
        onDone: [
          {
            target: 'finish',
            actions: ['ok'],
          },
        ],
        onError: [],
        timeout: '0',
      },
      finish: { type: 'final' },
    },
  },
  {
    promises: {
      prom: async () => true,
    },
    actions: {
      ok: ctx => {
        ctx.val = 'true';
      },
    },
  },
);
// => 'inactive'


Usage (serve)


import { createMachine, interpret } from '@bemedev/fstate';
const toggleMachine = createMachine({...});
//Serve infer the return type (the context is the return type of the function)
//Also it infers the fact that serve will be an async function or not
//Here before the states contain an async one,
//"service" will be an async function.
const service = serve(machine); // (args: number)=>Promise<{ val: string }>
(()=>await service(2))() // expected = { val: 'true' }

Readme

Keywords

none

Package Sidebar

Install

npm i @bemedev/fstate

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

35 kB

Total Files

16

Last publish

Collaborators

  • bemedev