Specifies the initial conversion action explicitly

By default, if the initial state is not specified, the state machine will be none, no lifecycle events will be triggered during the build, and you need to provide an explicit transition action to exit the state

  var fsm = new StateMachine({
    transitions: [{name: 'init'.from: 'none'.to: 'A' },
      { name: 'step'.from: 'A'.to: 'B' },
      { name: 'step'.from: 'B'.to: 'C'}}]); fsm.state;// 'none'
  fsm.init();   // Display triggers the 'init()' conversion action
  fsm.state;    // 'A'
Copy the code

Implicitly specifies the initial conversion action

If you specify the name of the initial state (as shown in most of the examples in this document), you create an implicit init transformation action that, along with its associated lifecycle events, fires during the build state machine.

This is the most common initialization strategy and you should use it 90% of the time.

  var fsm = new StateMachine({
    init: 'A'.transitions: [{name: 'step'.from: 'A'.to: 'B' },
      { name: 'step'.from: 'B'.to: 'C'}}]);// During build the 'init()' conversion is triggered: from 'none' to 'A'
  fsm.state;    // 'A'
Copy the code

Initialization and state machine factory

Each construction instance of the state machine factory triggers the INIT transformation action.

  var FSM = StateMachine.factory({
    init: 'A'.transitions: [{name: 'step'.from: 'A'.to: 'B' },
      { name: 'step'.from: 'B'.to: 'C'}}]);var fsm1 = new FSM(),   // fsm1 'init()' conversion action is triggered: conversion from 'none' to 'A'
      fsm2 = new FSM();   // fsm2 'init()' conversion action is triggered: conversion from 'none' to 'A'
Copy the code