Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Separate visual components from glue components #547

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

Closed
misskniss opened this issue Mar 24, 2022 · 1 comment
Closed

Separate visual components from glue components #547

misskniss opened this issue Mar 24, 2022 · 1 comment
Assignees
Labels
site Area: frontend dashboard
Milestone

Comments

@misskniss
Copy link

misskniss commented Mar 24, 2022

RFC

As a developer I want to clearly separate the visual components from the glue components as we bring in V1 features into V2 so that we can easily story book those components that do not access global state or send API calls and keep our code lean and easy to develop.

glue component: term for components that access global state or send API calls and are thus not easy to unit test or storybook. They are also known as “connected,” “smart,” or “impure,” but I like “glue” to encourage us to only use them as a glue layer between logic and view, and keep them as lean as possible. Glue components send messages, render org data and error messages.

visual component: components that don’t use global state or send API calls. not “pure” components because they can hold component state, such as a toggle button that you can click on or off or an input that can hold unsubmitted text. What they render depends only on their props and that kind of local user interaction, resulting in components that take maximize what we can easily unit test and put in Storybook. (It may also use the theme, which is delivered via Context Provider, and which unit tests and Storybook can handle.)

Further:
For separation of concerns, use the global state machines to encapsulate API calls. For instance, the Organizations machine knows how to add, delete, update, and read organizations from the backend, and the glue components do not (they merely send messages like "GET_ORGANIZATION" and render either organization data or error messages.

This will mean:

  • DRYer component code - instead of two page components writing the same promise handling code, the global state machine writes it once
  • leaner and easier to read glue components - I expect sending messages to the global state machine and receiving its state to amount to less code and fewer conditions in the components than handling the API calls there
  • the ability to change the API contract with minimal impact on the frontend codebase - just edit the global state machine
@greyscaled
Copy link
Contributor

I'm gonna mark this as complete, since the items are done and we're using the proposed state management solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
site Area: frontend dashboard
Projects
None yet
Development

No branches or pull requests

3 participants