Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate @xstate/inspect-Tooling #3

Open
bemayr opened this issue Feb 19, 2022 · 1 comment
Open

Integrate @xstate/inspect-Tooling #3

bemayr opened this issue Feb 19, 2022 · 1 comment
Assignees

Comments

@bemayr
Copy link
Owner

bemayr commented Feb 19, 2022

Idea

It should be possible to visualize Machines using @xstate/inspect.

Research

@bemayr bemayr self-assigned this Feb 19, 2022
@bemayr
Copy link
Owner Author

bemayr commented Feb 19, 2022

Debugging the Inspector Connection

After struggling with the format of the JSON Data that needs to be sent to the inspector I did some inspection via patching iframe.postMessage and window.onmessage and received the following JSON results:

Inspector Outputs ➡️

xstate.register

{
  "type":"xstate.inspecting"
}

xstate.event

{
  "type":"xstate.event",
  "event":"{\"name\":\"TOGGLE\",\"data\":{\"type\":\"TOGGLE\"},\"$$type\":\"scxml\",\"type\":\"external\",\"origin\":\"x:7\"}"
}

Inspector Inputs ⬅️

service.register

{
  "type": "service.register",
  "machine": "{\"id\":\"machine\",\"key\":\"machine\",\"context\":{\"count\":0},\"type\":\"compound\",\"initial\":\"inactive\",\"history\":false,\"states\":{\"inactive\":{\"id\":\"machine.inactive\",\"key\":\"inactive\",\"type\":\"atomic\",\"history\":false,\"states\":{},\"on\":{\"TOGGLE\":[{\"target\":[\"#machine.active\"],\"event\":\"TOGGLE\",\"actions\":[],\"source\":\"#machine.inactive\",\"internal\":false,\"eventType\":\"TOGGLE\"}]},\"transitions\":[{\"target\":[\"#machine.active\"],\"event\":\"TOGGLE\",\"actions\":[],\"source\":\"#machine.inactive\",\"internal\":false,\"eventType\":\"TOGGLE\"}],\"entry\":[],\"exit\":[],\"activities\":[],\"order\":1,\"invoke\":[]},\"active\":{\"id\":\"machine.active\",\"key\":\"active\",\"type\":\"atomic\",\"history\":false,\"states\":{},\"on\":{\"TOGGLE\":[{\"target\":[\"#machine.inactive\"],\"event\":\"TOGGLE\",\"actions\":[],\"source\":\"#machine.active\",\"internal\":false,\"eventType\":\"TOGGLE\"}]},\"transitions\":[{\"target\":[\"#machine.inactive\"],\"event\":\"TOGGLE\",\"actions\":[],\"source\":\"#machine.active\",\"internal\":false,\"eventType\":\"TOGGLE\"}],\"entry\":[],\"exit\":[],\"activities\":[],\"order\":2,\"invoke\":[]}},\"on\":{},\"transitions\":[],\"entry\":[],\"exit\":[],\"activities\":[],\"order\":-1,\"invoke\":[]}",
  "state": "{\"actions\":[],\"activities\":{},\"meta\":{},\"events\":[],\"value\":\"inactive\",\"context\":{\"count\":0},\"_event\":{\"name\":\"TOGGLE\",\"data\":{\"type\":\"TOGGLE\"},\"$$type\":\"scxml\",\"type\":\"external\"},\"_sessionid\":\"x:7\",\"event\":{\"type\":\"TOGGLE\"},\"historyValue\":{\"current\":\"inactive\",\"states\":{}},\"history\":{\"actions\":[],\"activities\":{},\"meta\":{},\"events\":[],\"value\":\"active\",\"context\":{\"count\":0},\"_event\":{\"name\":\"TOGGLE\",\"data\":{\"type\":\"TOGGLE\"},\"$$type\":\"scxml\",\"type\":\"external\"},\"_sessionid\":\"x:7\",\"event\":{\"type\":\"TOGGLE\"},\"historyValue\":{\"current\":\"active\",\"states\":{}},\"children\":{},\"done\":false,\"changed\":true},\"children\":{},\"done\":false,\"changed\":true}",
  "sessionId": "x:7"
}

service.event

{
  "type": "service.event",
  "event": "{\"name\":\"TOGGLE\",\"data\":{\"type\":\"TOGGLE\"},\"$$type\":\"scxml\",\"type\":\"external\",\"origin\":\"x:9\"}",
  "sessionId": "x:7"
}

service.state

{
  "type": "service.state",
  "state": "{\"actions\":[],\"activities\":{},\"meta\":{},\"events\":[],\"value\":\"inactive\",\"context\":{\"count\":0},\"_event\":{\"name\":\"TOGGLE\",\"data\":{\"type\":\"TOGGLE\"},\"$$type\":\"scxml\",\"type\":\"external\",\"origin\":\"x:9\"},\"_sessionid\":\"x:9\",\"event\":{\"type\":\"TOGGLE\"},\"historyValue\":{\"current\":\"inactive\",\"states\":{}},\"history\":{\"actions\":[],\"activities\":{},\"meta\":{},\"events\":[],\"value\":\"active\",\"context\":{\"count\":0},\"_event\":{\"name\":\"TOGGLE\",\"data\":{\"type\":\"TOGGLE\"},\"$$type\":\"scxml\",\"type\":\"external\",\"origin\":\"x:9\"},\"_sessionid\":\"x:9\",\"event\":{\"type\":\"TOGGLE\"},\"historyValue\":{\"current\":\"active\",\"states\":{}},\"children\":{},\"done\":false,\"changed\":true},\"children\":{},\"done\":false,\"changed\":true}",
  "sessionId": "x:7"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant