-
Notifications
You must be signed in to change notification settings - Fork 102
Visualize multiple actors #214
Visualize multiple actors #214
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/statelyai/xstate-viz/HpXiToc6jZvXt7qguQUZnHWT5qZR |
background: 'whiteAlpha.100', | ||
}} | ||
marginBottom="2" | ||
cursor="pointer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It IMHO would make slightly more sense to wrap the whole content of the ListItem
in Link
- if you are using the Link
. That way you wouldn't have add cursor: pointer
on this element and onClick
would be placed on a slightly more appropriate (semantically) element
src/simulationMachine.tsx
Outdated
stopServices(); | ||
machines.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be moved into the block responsible for handling the INTERPRET
machine - we probably want to always call this logic then, so I'm not sure if lifting this up as an additional command that can be dispatched by the parent brings much to the table. And when analyzing this part of the code having them grouped would make it slightly easier to follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this; clearing the machines seems to be the responsibility of a 'STOP'
event, not an 'INTERPRET'
event. We can refactor later if we need to here.
src/Graph.tsx
Outdated
export async function getElkGraph( | ||
rootDigraphNode: DirectedGraphNode, | ||
): Promise<ElkNode> { | ||
const rectMap = getRectMap(); | ||
const rectMap = await getRectMap(rootDigraphNode.id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any particular reason behind this change? I don't see it immediately when reading through those changes and it seems that it either is not needed or it has fixed some race condition - but it's hard to tell without knowing more context behind this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this change, when switching between actors, getElkGraph()
is called when the previous graph is destroyed and the new graph isn't yet rendered; therefore, getRectMap(...)
is useless and calling .width
was throwing an error (can't read .width
of undefined
).
This was introduced to fix that consistent error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see - we send the GRAPH_UPDATED
in the useEffect
but the last render that did happen was rendering based on the "success" state of the previous layout.
The used solution IMHO tries to fight the React and tries to wait, implicitly, on what should happen most of the time - but there are no conceptual guarantees that this will actually happen. For instance - we can click on another actor in the meantime and create a race condition.
It would be better if we could just avoid any chance of such things happening by making the synchronization of the DOM and Elk layouts more explicit, like for example here:
92d434a
I think it would be possible to avoid those duplicated effects but we'd have to implement derived state from props pattern and we'd have to avoid rendering based on state.matches('success')
. So I've chosen a solution closer to XState, at the expense of some wasted rerenders in React.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's have this as a refactor item
Should we be considering adding parent-child awareness to this PR? When visualising this code: import { createMachine } from "xstate";
const childMachine = createMachine({
initial: "idle",
states: {
idle: {},
},
});
const parentMachine = createMachine({
invoke: {
src: childMachine,
},
}); I see the child machine on screen first |
The parser is ready for grabbing this kind of info: |
The potential issue is when we have something like this: const parentMachine = createMachine({
initial: 'wait',
states: {
wait: {},
active: {
invoke: {
src: childMachine,
}
}
}
}); The This will probably cause confusion, but short of requiring Also, |
@davidkpiano Did you see the XState parser PR above? I haven't got it set up for invokes yet but it certainly will be able to handle it |
Should probably put this in a separate PR though, no need to hold up this one |
Ready for re-review |
The code below is supposed to generate 4 actors but it spawns only 3. import { createMachine, assign, spawn } from "xstate";
const machine = createMachine({
id: "test machine",
initial: "b",
context: { ref: null },
states: {
a: {
on: {
GO: "b",
},
},
b: {
on: {
GO: "a",
},
},
},
});
const child = createMachine({
id: "child",
initial: "c",
states: {
c: {
entry: assign({
ref: () => spawn(child2),
}),
},
},
});
const child2 = createMachine({
id: "child2",
initial: "d",
states: {
d: {},
},
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Holding this until the bug with the number of actors is fixed.
…r-of-actors-in-the-tab Show the number of actors in the tab
https://github.com/davidkpiano/xstate-viz into davidkpiano/sta-161-not-all-actors-being-shown-in-the
The issue here is that const child = createMachine({
id: "child",
initial: "c",
+ context: {},
states: {
c: {
entry: assign({
ref: () => spawn(child2),
}),
},
},
}); It works as expected with that fix ^ |
ok. following the discussion we had on Discord, this will be the default in v5. Ship it. |
Add changeset + tests for #214
CleanShot.2021-08-28.at.08.37.01.mp4
Stopped actors: