Design exploration: Scalar schema for lens-parameterized data#3885
Design exploration: Scalar schema for lens-parameterized data#3885
Conversation
Explores 4 distinct architectures for a new Scalar schema type to handle 'lens' use cases in grid/spreadsheet applications: 1. Entity subclass with compound PK + ScalarRef wrapper (recommended) 2. Collection-like non-Entity with lens map 3. Entity with lens map field + fieldMerge protocol 4. Query-like wrapper with ScalarNormalizedValue Each approach is analyzed for normalization/denormalization flow, store layout, merge behavior, type safety, MemoCache interaction, and performance characteristics. Recommends Approach 1 as primary because it requires zero changes to normalizr internals, zero MemoCache modifications, and leverages existing Entity lifecycle fully. Co-authored-by: Nathaniel Tucker <me@ntucker.me>
|
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3885 +/- ##
=======================================
Coverage 98.11% 98.11%
=======================================
Files 153 153
Lines 2913 2913
Branches 565 565
=======================================
Hits 2858 2858
Misses 11 11
Partials 44 44 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Motivation
A primary use case is displaying vast amounts of information in a grid/spreadsheet. Each row is represented as an entity. However, some columns need to show relational data parameterized by a user-selected "lens" entity -- e.g., "what % of Company X is in Portfolio Y?" The user selects which portfolio (lens) to view, which changes the column data.
Current schema primitives don't handle this well:
Query+Allscans are O(n) per cell -- unacceptable for large gridsSolution
Explored 4 distinct architectures for a new
Scalarschema type, each analyzed for normalization/denormalization flow, store layout, merge behavior, type safety, MemoCache interaction, and performance:Entity subclass with compound PK +
ScalarRefwrapper (recommended) -- Each (row, lens) combination is a standard entity with compound pk. AScalarRefwrapper handles denormalize indirection. Zero changes to normalizr/MemoCache.Collection-like non-Entity with lens map -- Follows Collection pattern, stores lens-keyed value map. Requires MemoCache args-awareness.
Entity with lens map field +
fieldMergeprotocol -- Stores all lens values as a map on the parent entity. Introduces a generalfieldMergeextension point on Entity.merge.Query-like wrapper with
ScalarNormalizedValue-- Stores{pk, stableFields}on parent, recomputes desired pk during denormalize. Requires MemoCache modifications.Recommendation: Approach 1, because it requires zero changes to normalizr internals, zero MemoCache modifications, supports per-lens invalidation/expiry, and leverages the full Entity lifecycle.
Open questions
fieldMergebe added as a standalone feature regardless of Scalar approach?ScalarvsIntersectionvsLensEntityEntity.denormalizebe extended to pass parent context to nested schemas?'__'vs'\x00'vs multi-character)