首页 > 其他分享 >[XState] raise event: trigger an action immediately when reach target state

[XState] raise event: trigger an action immediately when reach target state

时间:2022-11-26 18:00:49浏览次数:66  
标签:raise reach when middle action immediately event target

import { Machine, actions } from "xstate";
const { raise } = actions;

// Demostrate `raise` action
const stubbornMachine = Machine({
  id: "raisedmo",
  initial: "entry",
  states: {
    entry: {
      on: {
        STEP: {
          target: "middle",
        },
        RAISE: {
          target: "middle",
          // immediately invoke the NEXT event in 'middle'
          actions: [raise("NEXT")],
        },
      },
    },
    middle: {
      on: {
        NEXT: "last",
      },
    },
    last: {
      on: {
        RESET: "entry",
      },
    },
  },
});

The raise() action creator queues an event to the statechart, in the internal event queue. This means the event is sent immediately on the current “step” of the interpreter.

https://stately.ai/viz/cced7743-87b5-41ad-b09a-c9bdf0ace635

 

标签:raise,reach,when,middle,action,immediately,event,target
From: https://www.cnblogs.com/Answer1215/p/16927908.html

相关文章