Open AlexCLeduc opened 4 years ago
I really like the overall idea of all of this. I like the structure you laid out as starting point.
- Using recursive utils/ and components/
I like this idea and we should try it out. I'm unsure how easily manageable it will be to keep separate utils and components but I think it's worth a shot
But I'm not understanding domain
and platform
completely. Are they basically utils and/or components but doesn't quite fit into either, so you throw them in there? Can you clarify your thoughts on the difference between the two and, (why and how) would something fit into one or the other, instead of utils or components?
Initially I was thinking domain would be more business-related concepts and platform would be globally setup stuff like analytics, but looking through our components dir right now, I like the kitchen sink approach and don't think business-related stuff needs to be separate.
OTOH, I think there are still groups of components and utilities that we'll want to colocate, and that are often imported together. Also, some components/utils require external setup, like DocumentDescription
or DocumentTitle
, or modules/singletons that hold state.
If we think those criteria merit separation, we can have something like
foundation | platform | domain
/
The criteria for going in this directory can be
let
)#header
selector)Been trying to develop some thoughts on this/sketch a proposed restructuring. Heavily based on earlier discussion. Not sure I'm settled on this, but I've started to spin my tires so it's probably a good time to put it back up for discussion.
Proposal: a recursive directory structure based on four types of directories
1) utils
components
platform
#header
node
2) have implicit dependencieslet
), or use the singleton patternutils
/components
/platform
/thematic sub-directoriesroutes
dir and the contained per-route thematic dirs under itsrc/charts
content's could probably be tossed in the root components
dir, or src/models
's in platform
, but both are "weighty" enough concepts to stand up on their ownSketch of proposed structure:
/client/src/
./utils/
./request_utils.js
./components/
./SomeComponent/
./SomeComponent.js
./SomeComponent.scss
./platform/
#header
node, depend on some non-explicit one-time initialization step, etc
2) have module level state (e.g. top level let
), or use the singleton pattern
3) modules that collocate utilities and components that are often/necessarily imported together./Search/
./analytics.js
./InfoBase/
./components/
ErrorBoundary
, etc../index_html/
./models/
./platform/
./ensure_loaded.js
./subjects/
./tables/
./routes/
./platform/
./StandardRouteContainer.js
and other route/nav components?./Infographic/
./utils/
./infographic_link.js
./Infographic.js
./PanelFilterControl.js
./Infographic.js
itself, could be inlined in it but kept separate for organization reasons./components
sub-dir, right? ./panels/
declare_panels
./charts/
./static/
./theme/
Seems good to me, just to make sure I understand, the root platform/
would have the explorer and search?
For models/
, would populate
files go into platform
? If it's just ensure_loaded
in platform
, I think ensure_loaded can just stay on the root of models/
I'd generally prefer to minimize the use of recursive subdirectories of components/
, platform/
, utils/
, etc if it's just 1 file in there just so the whole directory structure tree doesn't become too huge.
I think it's worth keeping charts/
and panels/
at root directory for more visibility
Agreed with @ktw1016 that charts/ panels can go in the root directory.
I disagree that single files should replace utils/components. Instead, I'd rather utils start out as utils.js
modules, and get "upgraded" to utils/
directories once they get large, in a way that doesn't lead to import refactors.
Archived doc draft from closed PR, to revisit when the repo is less active and a full directory reorg is more feasible. https://github.com/TBS-EACPD/infobase/blob/4efbe04269749a86da404f3aa431db465369dff4/docs/client/directory-structure.md
It's kind of difficult to figure out where something goes right now. I'd like to propose we reset our directory structure.
I don't have all the answers (warning: there will be conflicting ideas below). Here's a starting point for discussion:
infographic
andmetadata
What about core/ ? explorer-common/ ? search/ ? I have 3 patterns in mind to take care of the rest
1. Using recursive utils/ and components/
To avoid src/utils getting too large, we can try and have multiple
utils/
directories. If a utility becomes re-usable beyond its directory, it gets upgraded to a higher-level directory's utilities, until it ends up insrc/utils/
. For instance, utilities for defining new routes can be insections/utils
, because it won't be used outsidesections/
. Same thing goes for components.Since core/ has a lot of components that only get used in App.js, and a lot of bootstrapping stuff only used in
src/InfoBase
, most of it can be dumped intosrc/InfoBase/
's components and utils directories.Another benefit of this pattern is that removing a section or panel will also remove all of its specific utils/components.
2. domain/
one problem with just having plain utils/ and components/ is that we have plenty of tightly related tools that contain both plain functions and components:
For lack of a better idea, we can nest stuff like this under
src/domain/
. I think we'll end up with more of these as we grow, so I'd prefer not to keep them top-level.Note: Let's try and find a better name than domain
3. Platform/ (or foundation/)
Certain utils/components are gonna be used broadly and are more context-aware than simple functions. This could be another split point.
Think about
log_standard_event
)infograph_href
template)Conclusion ?
We can use any combination of recursion, domain, platform. If we use both domain and platform, we should make sure the difference is clear (e.g. should glossary/footnote utils go in domain, or platform?)
Here's a more detailed breakdown of the all the top level files (and core). Blank destination means leave it alone. If we have more opinions we can move this to a google doc or sheet. There is some stuff missing. For instance, we may decide to move some context-aware or smart components outside of
components/
and intoplatform/
ordomain/
.side-effects.js