-
Notifications
You must be signed in to change notification settings - Fork 47
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
Hierarchical POC #73
base: main
Are you sure you want to change the base?
Hierarchical POC #73
Conversation
machine = { ...machineInstant, send } Machine.State -> Machine machineState -> machineInstant machineState.value -> machineInstant.state Machine.StateValue -> Machine.State
You are a machine. This is awesome! Checking the code right now.
✅
Correct. Are we also representing the state as a array in case of a flat, single-level state machine?
Yeah, makes sense.
Yeah, we might need to use a pathfinding algorithm (opposed to just traversing the tree until we find the nodes).
Correct, assuming you meant that exist would be [b, b1] |
Hahaha thanks a lot!
Yep
How would the pathfinding algorithm work without traversing the tree though? This version does a depth-first search (assuming
Right, typo (will edit for posterity) |
We could traverse from the nodes and find the shortest path without necessarily traversing the whole tree from the top - but thinking about it, it seems like a premature optimization - Most likely the state tree won't be complex or big enough to benefit from this... |
Huh? xD I don't follow, wym by "find the shortest path"? To make sure we're on the same page we're taking about an algorithm that takes an input EDIT: Oh wait we have an additional information that the current state is
Yep exactly, but I think it's a good improvement nonetheless. |
Just a little poc I tried (not very tested), wanted to keep it fp let me know if you like it so either of us can take this forward!
I know this is the least important thing right now as it's for 1.2.0 but as usual I was bored and wanted to do something fun xD
(I have based it on
api-change-for-sendt
as you haven't merged it yet)Edit, A gist how it works:
We store the state of the machine in form of a tree. Where each node can be thought of a stateful submachine. Each node has
children
andstate
which is the identifier of the active child.So the final "state" ie an sequential array from outermost active node to innermost active node is derived via
Node.state
and is not the source of truth. (Might rename the propertystate
ofnode
to be something else becausenode.state
andNode.state(node)
read similar but are completely different)So essentially when an event comes we find out the
nextStateIdentifier
, then compute thenextState
from it, then diff it with thecurrentState
for entries and exits.So for the test case something like this happens...
The
Node.transition
part is completely pure (it gives[newNode, entries, exits]
) so it will help with testing (I'm thinking of some snapshot based testing) and also withshouldSend
as we could simply send it and see if the state changes.