none
The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Pass A Value In To An on In An XState Send Event

TODO: Pull subtitle into page object

Notes

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Pass A Value In To An on In An XState Send Event

This is how I'm sending data into an XState state machine
from an external source.  I use it, for example, when I'm 
getting new data coming in from a web socket

-- script
-- show

const { createMachine, interpret } = XState

const machine = createMachine(
  {
    predictableActionArguments: true,
    initial: 'alfa',
    context: {
      widget: false
    },
    states: {
      alfa: {
        on: {
          PING: {
            actions: ["registerPing"]
          }
        }
      }
    }
  },
  {
    actions: {
      registerPing: (context, event) => {
        console.log(event)
      },
    },
  }
)

const actor = interpret(machine).start()

actor.send({ type: "PING", extraData: "bravo" })


-- notes

- The biggest thing that caught me was that the
actions have to be inside their own object after
the one with the states and contexts, etc... in it

- I'm not sure if this is the ideal way to do
this, but it's the only way I could figure out how
to do it. I wouldn't be surprised to find out
I'm missing something 




-- head
-- src: /scripts/xstate_4_38_2_dist.js

-- ref
-- url: https://stately.ai/docs/xstate

-- ref
-- url: https://stately.ai/docs/category/xstate-actions

-- ref
-- url: https://stately.ai/docs/category/xstate-actors

-- ref
-- url: https://github.com/statelyai/xstate

-- ref
-- url: https://github.com/statelyai/xstate/issues/505

-- ref
-- url: https://xstate.js.org/docs/guides/events.html#api



-- categories
-- JavaScript 
-- XState 

-- metadata
-- date: 2023-08-26 21:42:18
-- id: 2uxz6ypl
-- site: aws
-- type: post
-- status: draft