Skip to content
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

codebase structure refactor #185

Open
the-vampiire opened this issue Dec 4, 2018 · 1 comment
Open

codebase structure refactor #185

the-vampiire opened this issue Dec 4, 2018 · 1 comment
Labels

Comments

@the-vampiire
Copy link
Contributor

Goals

  • readability
  • accessibility of related files
  • separation of path-associated Views from their constituent Components
  • intuitive navigation of grouped components

Guidelines

  • always use absolute imports from ./src/path/to/import

Structure

src/
  - views/
    - ViewName.jsx
    - ViewName/
  - components/
    - ViewName/
    - UI/
    - Utility/
    - Static/
  - queries/
  - mutations/
  - utils/
  - assets/
  - styles/
  - App.jsx
  - index.js
  • utils/: shared non component utilities (formatting)
  • styles/: shared SCSS and config
  • assets/: shared static assets
  • App.jsx: import views/ for Router
  • index.js: root export with wrappers and configuration

Queries and Mutations

  • only used in the component: write in the component file
  • shared by multiple components: write in queries/ or mutations/
    • queryName.js or mutationName.js
  • label the queries or mutations for easier debugging
query DescriptiveLabelName($input_name: input_type) {
  query(input: $input) {
    return_field
  }
}

mutation DescriptiveActionName($input_name: input_type) {
  mutation(input: $input) {
    return_field
  }
}

mutations

  • when calling a mutation of data owned by and returning a Type always request back
    • the id field
    • the fields that were updated
  • this will keep the cache consistent and remove the need for callback-based updates

views/

  • /ViewName.jsx
    • imports children and renders a path-associated view
  • /ViewName/
    • index.jsx: same as ViewName.jsx
    • include non-component support files specific to the view (custom styling, assets, animations)

components/

  • ViewName/: components only used in a single View
  • Category/: shared components under a common category
    • UI/: base UI components (buttons, cards)
    • Utility/: utility components (<Request />, <Modal />)
    • Static/: static homepage components
  • ComponentName/: complex shared components not necessarily under a view or category (rare)

component directories

  • each directory should have a default export from index.jsx
  • components should contain one SCSS file per depth of directory

component definitions within the directories

  • components should mostly remain in flat .jsx files
  • if a component grows in complexity to require sub-components create a dir by its name to contain them
    • follows component directory guidelines
    • this new dir should now contain the SCSS styles for itself and sub-components
    • rarely extend deeper than one sub-directory component
@the-vampiire
Copy link
Contributor Author

all newsfeed refactoring using the new structure. afterwards converting the remaining code

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

No branches or pull requests

1 participant