-
Notifications
You must be signed in to change notification settings - Fork 8
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
refactor: Move fetchNearestIntersection
to the state machine
#2745
refactor: Move fetchNearestIntersection
to the state machine
#2745
Conversation
onDone: { | ||
actions: assign({ | ||
detourShape: ({ event }) => event.output, | ||
invoke: [ |
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.
Discussion about this:
This change will cause fetch-nearest-intersection
to be invoked any time a waypoint is placed. This is a change from the hook implementation, where it was only called when the start point was placed (or changed).
I don't think it's a huge problem for right now, which is why I'm PR'ing this as-is, but I do wonder if the Right Solution is to add another state, so that the drawing-detour states would be something like:
No Start Point
Start Point Only
<-- callsfetchNearestIntersection
and eventuallyfetchUnfinishedDetour
Some Waypoints
<-- callsfetchDetourDirections
End Point Placed
<-- callsfetchFinishedDetour
@mbta/skate-developers thoughts?
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.
Hmmm, this also seems to leave open a race condition, where if the end point is placed before the fetch-nearest-intersection
actor finished its work, then the fetch-nearest-intersection
actor's work is ignored, and we end up with From null
. Is there a way to force an actor to keep plugging on even if the state machine has moved to a different state?
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.
You want to spawn an actor
A while ago, I tried doing this refactor once and ran into this, and was struggling to grasp the concepts and how to use spawn
for this, maybe you'll have better luck, or we can try pairing on it.
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.
If we want to avoid spawning, we'll probably need to do the intermediate state thing,
which could be done within the place start point
state and use onDone
to transition out of place start point
and into place waypoint
Spawning has the benefit of not blocking the user on the intersection fetch, but then means we have to figure out how to store it and figure out how that gets serialized and persisted, so that we're not storing an actor state we don't mean to.
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.
Okay here's a silly question - because this tool is primarily (exclusively?) used by dispatchers, where the internet connection is reasonably reliable, can we roll forward with this as-is, and migrate towards spawn
later?
I think spawn
is the right call in the long/medium term, but the spawn
contract is so different from invoke
that actually making that change is more complicated than I was expecting.
I think though that merging this as-is should unblock the things that are blocked, and changing to spawn
shouldn't change anything (aside from fixing the issues mentioned ☝️☝️)
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.
I think that's fine, would you document your reasoning inline? that might help future "us"?
My day is up, but I'll revisit this first thing tomorrow
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.
Okay! I'll be around a little bit tomorrow, so let's see how we're feeling about this tomorrow.
@@ -1288,6 +1288,10 @@ describe("DiversionPage", () => { | |||
fireEvent.click(originalRouteShape.get(container)) | |||
}) | |||
|
|||
await act(async () => { |
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 is why I noticed this, because if this await act
is moved down below the second fireEvent.click
, then the test fails.
Coverage of commit
|
Asana Ticket: https://app.asana.com/0/1148853526253420/1207539825544288/f