chore: cleanup app.js #1050
Labels
No labels
1week
2weeks
Failed compliance check
IP cameras
NATS
Possible security concern
Review effort 1/5
Review effort 2/5
Review effort 3/5
Review effort 4/5
Review effort 5/5
UI
aardvark
accessibility
amd64
api
arm64
auth
back-end
bgp
blog
bug
build
checkers
ci-cd
cleanup
cnpg
codex
core
dependencies
device-management
documentation
duplicate
dusk
ebpf
enhancement
eta 1d
eta 1hr
eta 3d
eta 3hr
feature
fieldsurvey
github_actions
go
good first issue
help wanted
invalid
javascript
k8s
log-collector
mapper
mtr
needs-triage
netflow
network-sweep
observability
oracle
otel
plug-in
proton
python
question
reddit
redhat
research
rperf
rperf-checker
rust
sdk
security
serviceradar-agent
serviceradar-agent-gateway
serviceradar-web
serviceradar-web-ng
siem
snmp
sysmon
topology
ubiquiti
wasm
wontfix
zen-engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
carverauto/serviceradar#1050
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?
Imported from GitHub.
Original GitHub issue: #2891
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/issues/2891
Original created: 2026-02-22T18:54:36Z
app.js is huge and needs to get cleaned up:
Phase 1: The Target Folder Structure
We are going to break your
assets/jsfolder into logical domains. Here is what your directory structure should look like when we are done:Phase 2: Extracting the Code (Step-by-Step)
1. Extract Utilities (
assets/js/utils/formatters.js)Move all those detached helper functions at the top of your file into their own module.
2. Extract Shaders and Custom Classes (
assets/js/lib/deckgl/PacketFlowLayer.js)Move the
packetFlowVS,packetFlowFS, and thePacketFlowLayerclass into their own file.3. Extract Individual Hooks (
assets/js/hooks/MapboxFlowMap.js)Take each key inside your
Hooksobject and make it the default export of its own file.4. The
hooks/index.jsAggregatorInstead of manually defining the
Hooksobject inapp.js, create anindex.jsfile inside yourhooksdirectory that imports them all and exports a single object.5. Your New, Beautiful
app.jsNow, your
app.jsgoes from 4,300 lines down to about 40 lines. It strictly handles bootstrapping Phoenix.Phase 3: Best Practice for Massive Hooks (The "Class Wrapper" Pattern)
Look at your
GodViewBinaryStreamhook. It is nearly 1,500 lines long. While putting it in its own file solves the file size problem, putting 1,500 lines of complex WebGL, WebAssembly, and WebSocket logic inside a basic LiveView Hook object is an anti-pattern.Best Practice: The Hook object should only be "glue" between LiveView and the DOM. The actual logic should live in an ES6 Class.
Here is how you refactor giant hooks:
Create a class
GodViewRenderer(assets/js/lib/GodViewRenderer.js):Then, your actual LiveView Hook (
assets/js/hooks/god_view/GodViewBinaryStream.js) becomes incredibly clean:Summary of Benefits
await import('./GodViewRenderer')so you don't load 5MB of Deck.gl/Arrow code for users who never visit the map page), it's drastically easier.liveSocketis connected.