Research if we can scan features and automatically add views to view registry #607
Labels
No labels
_CRITICAL_
API
app
backEnd
Blocked, waiting for further changes
bug
cleanup
close
design
duplicate
enhancement
feature request
frontEnd
help wanted
invalid
low priority
needs input
needs review
project documentation
question
research
reviewed
script
security
SQL
style
testing
topLevel
wontfix
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Andras/BoundlessFlowCampus2K#607
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
We currently have to manually add views to the views/viewRegistry constants. Although this isn't too big of a hassle, it would be nice if we only have too add the view to the features folder.
This should not be merged, but please create a branch where we can test this approach.
Recommended approach is Webpack require.context
Webpack has a built in feature called require.context that can scan a folder and import all files matching a pattern at build time.
The idea is to create a new file features/viewRegistry.js that scans features/ for all *View.js files, checks if they export a viewMeta object and if they do, adds them to views and viewRegister automatically. Dashboard.js then just imports from the registry instead of listing everything manually.
Each view needs one new export so the registry knows to pick it up, javascriptexport const viewMeta = { name: 'TemperatureView' };
Positives
No external dependencies
Only one place to maintain
Removes a lot of manual imports from Dashboard.js
The viewMeta check filters out hooks and other non-view files automatically
Negatives
require.context only works in Webpack. If the project switches to something else this would need to be rewritten
The dropdown order becomes alphabetical by file path instead of the current order
Special cases still have to stay in Dashboard
Does this require a new dependency?
Changing an existing dependency?
Give me a TLDR compliant explanation.
No new or changed dependencies, Webpack is already included as a dependency in react-scripts.
@c24carso have you created a branch that we can test?
Will redo it on the current branch since it's old now.
This is implemented . I close this issue #827 (comment)