Normalisation Strategy
Last updated
Key principle: When centralising duplicated logic, we normalise to a single canonical implementation even when variants differ slightly.
The duplicated calculations aren't always exactly identical - they have minor variations in:
Access patterns (canvas destructured vs query.canvas direct access - same value, different syntax)
Optional chaining depth (canvases?.[...] vs transformedManifest?.canvases[...])
Fallback values (some have || '', others allow undefined - need to determine which is correct)
We still centralise these because:
They compute the same logical value - just with different syntax
Normalisation prevents drift - variations can grow into bugs over time
Reduces cognitive load - one canonical way to access the value
Makes changes easier - update once, not in 4 places
For each duplicated value, we choose the most defensive/complete version:
currentCanvas
canvases?.[i] vs transformedManifest?.canvases[i] (accessing same data via different paths)
Use transformedManifest?.canvases[i]
More explicit about data source
mainImageService
With/without || '' fallback
Include || '' only if downstream code requires it
ZoomedImage has fallback because convertRequestUriToInfoUri expects string. IIIFViewer doesn't need it. Check actual usage before adding fallback.
hasMultipleCanvases
Not in context
Add to context
Calculated in IIIFViewer, used in multiple components
For each normalised value, verify that:
Original behaviour preserved - components work identically with context version
Edge cases handled - undefined/null cases don't break
Type safety maintained - TypeScript types are correct
Fallback behaviour tested - verify fallbacks are only added where genuinely needed
Next: 03 - Naming Conventions
Last updated