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

Define a new folder structure #76

Open
thePeras opened this issue Apr 26, 2023 · 1 comment
Open

Define a new folder structure #76

thePeras opened this issue Apr 26, 2023 · 1 comment
Assignees

Comments

@thePeras
Copy link
Member

Leave suggestions below

@Naapperas
Copy link
Member

Looking at the current structure of the project, there are some alarming things, namely the fact that the utilities package is a large part of the code base.

With that in mind, one possible solution is to:

  • Have code that is used throughout the whole website in a common package;
  • Code related to a single page should be separated into its own file; these files could live in a pages directory;
  • Things like tables can occur several times. In order to keep the same styles and structure, there could be a components directory containing code for these situations: each page would only need to include/run it when needed;
  • non-UI related code should live separately from UI code: things related to being authenticated and such could live in a auth folder;
  • This is just a personal opinion but if possible there should be any "utils" code at all. ON the rare occasion that it makes some sense to have said code, you could make some "localized" (i.e., annex to the code or bits of code that use it) utils package/file.

One other thing to keep in mind is to not run every bit of javascript in every page since this can slow down page loads. Instead (and as @LuisDuarte1 suggested) we should have a mapping from URLs to "Page scripts". My 2 cents on this is to have a centralized "page registry", kinda like:

// pageRegistry.js

const pageMapping = {} // mapping: URL Regex -> Function

const registerPage = (pageUrlRegex, pageLoader) => pageMapping[pageUrlRegex] = pageLoader;

const loadPage = (pageUrl) => {

    for (const urlRegex of pageMapping) {
        if (pageUrl.match(urlRegex)) {
            pageMapping[pageUrlRegex]();
            return;
        }
    }
}

The code might not be correct but you get the idea

This way, when a page loads, you only need to run the corresponding loader.

This is all based on personal experience and I invite other people to argue about the pros and cons of this structure and provide their own solutions.

P.S.: Typescript is cool :P

@ttoino ttoino added this to the Version 1 milestone Jun 26, 2023
@ttoino ttoino self-assigned this Jun 26, 2023
@ttoino ttoino changed the title Define a new folder structure for content-scripts folder Define a new folder structure Nov 13, 2023
@ttoino ttoino removed this from the Version 1 milestone Jan 2, 2024
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 a pull request may close this issue.

3 participants