zoukankan      html  css  js  c++  java
  • [XState] Multiple Simultaneous States with Parallel States

    Can you walk and talk at the same time? If so, you've experienced what it's like to be in two states at the same time. Hopefully, those two states have no influence on the other. Whether or not you talk, you can walk, and vice versa. States that occur concurrently and have no affect on the other are known as "parallel states".

    Parallel states happen simultaneously. The machine is in all of the parallel states at the same time. To create a parallel state node, we set the type to 'parallel' and then remove the initial state. There's no need for an initial property when you're in all the child states at the same time.

    const { Machine } = require("xstate");
    
    const spaceHeaterMachine = Machine({
      id: "spaceHeater",
      initial: "poweredOff",
      states: {
        poweredOff: {
          on: { TOGGLE_POWER: "poweredOn" }
        },
        poweredOn: {
          on: { TOGGLE_POWER: "poweredOff" },
          type: "parallel", // mark parallel
          states: {
            heated: {
              initial: "lowHeat",
              states: {
                lowHeat: {
                  on: { TOGGLE_HEAT: "highHeat" }
                },
                highHeat: {
                  on: { TOGGLE_HEAT: "lowHeat" }
                }
              }
            },
            oscillation: {
              initial: "disabled",
              states: {
                disabled: {
                  on: { TOGGLE_OSC: "enabled" }
                },
                enabled: {
                  on: { TOGGLE_OSC: "disabled" }
                }
              }
            }
          }
        }
      }
    });

  • 相关阅读:
    面向对象概述(课堂笔记)
    final
    static方法
    Ubuntu中Qt5.7.0无法输入中文
    Ubuntu中Qt+opencv图像显示
    Ubuntu中Qt新建窗体提示lGL错误
    Ubuntu中Qt5.7.0的安装及opencv2.4.13配置
    Ubuntu16.04删除客人会话
    ffmpeg的安装--opencv视频处理必备
    CentOS+OpenCV图像的读入、显示
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12216235.html
Copyright © 2011-2022 走看看