by tracker1 · 2y ago · 0 comments
Instead of...
tests
auth
login.test.ts
controllers
auth
login.ts
components
auth
login.tsx
...
You would have... feature
auth
login
login.data.ts
login.data.test.ts
login.controller.ts
login.controller.test.ts
login.form.tsx
login.form.test.ts
...
That, in my opinion should include tests... You can have shared components, etc... or break up sub-projects.. but within a given project, I prefer features/concerns over class/data type.edit: In the above case, controller is really a higher order hook along with a higher order function component that will get call the hook, then pass the state to the separate component for render/events.
If you're doing server components, may want something similar but different depending on architecture or out of the box structures.
features
auth
login
libraries
dates
strings
...
I don't like to have a package / library called `utils`, `commons`, `shared` and other generic words that does not indicate me what's the context of this folder.Move your pure function utilities to a feature-agnostic folder whenever it makes sense, and import them into your feature.
I agree that's where the problems begin though :)
feature/shared/utils/foo.ts
feature/shared/utils/format-date.ts
feature/shared/ux/(template|region|etc)/foo.ts
Where ux are for components that may be referenced in multiple areas, or generic templates, etc. and shared are for utility methods, functions, etc.At the time I was even thinking that tests should be part of the same file where the component or feature is implemented. There were ways to make this work, but it required a lot of configuration at the time.