-
Notifications
You must be signed in to change notification settings - Fork 0
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
pull up cleanup functions #1
base: master
Are you sure you want to change the base?
Conversation
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.
So the change is basically to switch from useState
to useRef
and manual re-render, right?
return next | ||
}) | ||
const del = <T extends Record<string, unknown>>(sync: () => unknown, map: Map<string, Mgmt<T>>, id: string) => { | ||
map.delete(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.
this is not enough: when stopping to follow a plant or robot, the machine-runner needs to be destroyed right here
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.
ah I see, the missing cancel
call
if (effectHasRun) return | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
else effectHasRun = true | ||
let alive = true; |
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.
why is this needed? shouldn’t it be enough to track cancellation callbacks and calling them?
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 needed so that runPlant
and runRobot
know when the useEffect's
lifetime ends.
The alternative to this will be a sync runPlant
and runRobot
, as you told me the last time, returning a cancellation callback which when called will flip a similar flag, although the alive
flag will be inside each of runPlant
and runRobot
@@ -146,22 +157,36 @@ export const App = ({ actyx }: Props) => { | |||
myPlant = persistentId('plantId') | |||
console.log('restarting: plant', myPlant) |
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 needs to update the plantId state as well.
if (!old) return | ||
const readyState = { ...old, type: 'ready' as const, state }; | ||
map.set(id, readyState); | ||
sync() |
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.
should probably be conditional on the state actually being different
@Kelerchian I pushed a much smaller fix, see 1c6f11a#diff-26ad4b834941d9b19ebf9db8082bd202aaf72ea0ddea85f5a8a0cb3c729cc6f2R143-R154 |
The main change is the switch from
|
No description provided.