normalize-compound-operations
Preserve relative state relationships when performing compound operations instead of restoring absolute values.
When to Use
When performing operations that affect multiple related elements (like deleting or moving items in a timeline), avoid trying to restore exact absolute values. Instead, focus on maintaining the relative spacing and relationships between elements.
The Problem
Attempting to restore absolute positions/values after compound operations often introduces bugs:
- Gaps appear in sequences
- Spacing becomes inconsistent
- State becomes fragile and hard to maintain
The Solution
- Identify relative relationships - Determine what spacing, order, or distance relationships must stay constant between elements
- Track offset changes - When one element moves, calculate how this affects others relatively
- Shift together - Move or adjust all affected elements by the same relative amount, preserving gaps and spacing
- Verify relationships - Check that relative spacing and order remain intact, not that absolute values match
Example
When deleting an item from a timeline:
- Wrong: Try to restore exact frame numbers (1, 2, 3, 4...)
- Right: Shift remaining items left by the deleted item's width while preserving the gaps between them
Tips
- Think in terms of "distance between" rather than "position at"
- Use deltas/offsets rather than absolute coordinates
- Test by checking relative differences, not absolute values
- This approach makes operations composable and reversible