Skip to content

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

Merged
merged 1 commit into from
May 23, 2022

Conversation

presleyp
Copy link
Contributor

@presleyp presleyp commented May 23, 2022

Closes #1491

@presleyp presleyp self-assigned this May 23, 2022
@presleyp presleyp requested a review from a team as a code owner May 23, 2022 16:53
Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma left a 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)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@presleyp presleyp merged commit 7ac3cbe into main May 23, 2022
@presleyp presleyp deleted the polling/presleyp/1491 branch May 23, 2022 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make workspace XService not poll when unnecessary
3 participants