-
Notifications
You must be signed in to change notification settings - Fork 46
Refactor frontend #4009
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
base: develop
Are you sure you want to change the base?
Refactor frontend #4009
Conversation
7a4c13d to
677f360
Compare
677f360 to
49aeef5
Compare
JoeyStk
left a comment
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.
Thank you very much for this PR! I think it's a great step forward for us in helping us keeping our codebase clean 🚀 I think you did a wonderful job 💛
This isn't a full review yet, but I already wanted to give you some preliminary feedback :). After running the server, I get the following error in the web console.
Details
Uncaught (in promise) DOMException: Document.querySelectorAll: '[data-js-*]' is not a valid selector
_callee2 index.ts:103
i main.51245facc06e27bf6459.js:557
o main.51245facc06e27bf6459.js:558
__awaiter main.51245facc06e27bf6459.js:587
__awaiter main.51245facc06e27bf6459.js:569
bootstrapModules index.ts:100
ts index.ts:163
ts index.ts:159
Webpack 5
main.51245facc06e27bf6459.js:687
__awaiter main.51245facc06e27bf6459.js:569
bootstrapModules index.ts:100
ts index.ts:163
(Async: EventListener.handleEvent)
ts index.ts:159
Webpack 5
Thank you for catching this. I added this at the end and did not properly check. Unfortunately there are no wildcards for attribute selection the way I imagined it ( |
JoeyStk
left a comment
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.
Still not a full review, but here is one thought of mine :)
docs/src/documentation.rst
Outdated
| For the generation of the Frontend Modules we use Typedoc and then the `myst-parser` tool to integrate them into the sphinx documentation. | ||
|
|
||
| The generation process is divided into two stages: | ||
| The generation process is divided into three stages: |
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.
| The generation process is divided into three stages: | |
| The generation process is divided into four stages: |
I think this should be four, right? At least we list four steps below :)
JoeyStk
left a comment
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.
Additionally I think it might help to rebase soon, but it's probably not going to be a nice experience 😬
jonbulz
left a comment
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.
My two cents:
In general, I like the idea of having a registry.ts as source of truth. But I'd strongly suggest that we decide on one of two possible paths:
-
- We auto-generate the registry, but don't commit the file
-
- We commit the file, but in a human-readable form. If the file is still generated by some tool or automation, we need to make sure that the generated file is identical across different environments and operating systems. Alternatively, we could edit the registry.ts by hand if a new module is added (which shouldn't happen all that often)
I personally lean towards option 2 and "edit-by-hand", unless there is a very easy way to generate the file. If we want to ensure that the registry does not contain some typo or other mishap, we can add a pre-commit hook and/or a CI job that checks that.
In general, I think you did a great job in making the frontend more structured and maintainable! Thank you very much! :)
I still didn't get around to investigate the way you implemented what you call "template modules", but the "feature modules" are a good and useful abstraction IMO
Yes, I also tend towards getting rid of the automatic generation but making it human readable, especially as the validation logic I used in the node script for the automatic generation could be re-used in the pre-commit and/or CircleCI job. The registry form I envision: |
277b133 to
467da0a
Compare
Thank you very much for that tip :) I will keep doing regular rebases until merged |
Short description
This refactor provides a pattern for further frontend refactoring. Ts files are divided into template files and feature modules. Furthermore we now automatically generate a documentation for the frontend through integration of typedoc with our sphinx documentation for the backend files.
The goal of this refactor (and the subsequent refactoring of all feature modules) is/will be:
1.) To make it clear which ts file are used in which template (and vice versa)
2.) To reduce the amount of selector methods we crawl the DOM for
3.) Scope feature modules to a specific root element, to reduce the chance of accidentally attaching an eventListener to the wrong element
4.) To scope template modules to one specific template only
Proposed changes (main ones)
generateRegistry.ts(as npm script:generate:registry) that generates a fileregistry.tswhich contains a record of registered feature modules and make it part of the build processbootstrapModulesfunction in index.ts that dynamically imports and initializes feature modules that are need for the current pagesearch-query.tsrefactored as a feautre module anddata-js-search-queryattribute added on root element in template/templatefolder and set as entry-points inwebpack.config.jsonand then added the respective bundles in the templatesindex.tsthat are template modules or feature modulesdocs:frontendthat uses typedoc to generate *.md documentation files for the ts files and then use the myst-parser plugin to generate *.rst files with sphinx as part of our documentationSide effects
Faithfulness to issue description and design
There are no intended deviations from the issue and design.
How to test
integreat_cms/static/src/js/template/integreat_cms/static/src/js/feature/npm run build)tools/make_docs.shand see that it worksNext steps for Refactor
jsfolder that work based on eventListeners should be turned into feature modules (that excludes exported utility functions and the files that create preact components). This includes the following:search-query.ts) to the code:-
export const moduleName = <name-of-module>;-
const init = (root:HTMLElement) => { //register all eventListeners on or inside the root Element }-
export default init;/featuresdata-js-<moduleName>to the root element of the feature for wherever it is needed in the templatestools/run.shat least once to generate the new registry.ts filehtmxwherever we fetch from the backendwebpack-bundle-analyzerto consider if we could get rid of big external libraries that are not essential for us or at least only partially bundle them, to reduce bundle sizeResolved issues
Relates to: #2684
Pull Request Review Guidelines