-
Notifications
You must be signed in to change notification settings - Fork 887
refactor: Make workspace machine ephemeral to limit polling #1674
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
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.
LGTM
|
||
export const WorkspacePage: React.FC = () => { | ||
const { workspace: workspaceQueryParam } = useParams() | ||
const workspaceId = firstOrItem(workspaceQueryParam, null) | ||
|
||
const xServices = useContext(XServiceContext) | ||
const [workspaceState, workspaceSend] = useActor(xServices.workspaceXService) | ||
const [workspaceState, workspaceSend] = useMachine(workspaceMachine) |
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 because 'useMachine' accepts a machine instead of a service, it's not persistent?
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.
Yes, the service is instantiated in the component, and will thus end when the component is unmounted. In the other style, we instantiate the service in the StateContext
, so it outlives components.
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.
useMachine
turns a machine into a service, while useActor
and useInterpret
are ways of connecting to a service. The difference between the latter two is that useActor
will give you all the state and the component will rerender on any state change, while useInterpret
won't cause unnecessary rerenders, but you need selectors to get pieces of state.
Closes #1491