Skip to content

Settings Resolver

The settings resolver exports a machine that is intended to be used as the child of another machine. This is done by invoking the machine and then transitioning to the relevant states based on it's emitted events.

Usage

js
import { createMachine } from 'xstate';
import { settingsMachine } from '@fingermarkglobal/settings.resolver';

const restaurantMachine = createMachine({
  id: 'parent-machine',
  initial: 'settings',
  context: {
    serial: null,
  },
  states: {
    settings: {
      invoke: {
        id: 'settings-machine',
        src: settingsMachine,
        data: {
          serial: context => context?.serial,
        },
      },
      on: {
        SETTINGS_MACHINE_FAILURE: {
          target: 'failure',
        },
        SETTINGS_MACHINE_SUCCESS: {
          target: 'success',
        },
      },
    },
    failure: {
      //...
    },
    success: {
      //...
    },
  },
});

Context

Note this machine makes use of the data attribute which allows us to invoke child machines with exiting context.