Skip to content

refactor: consolidate initial value derivation logic#72

Merged
michaelbe812 merged 3 commits into
mainfrom
fix/consolidate-initial-value-logic
Sep 16, 2025
Merged

refactor: consolidate initial value derivation logic#72
michaelbe812 merged 3 commits into
mainfrom
fix/consolidate-initial-value-logic

Conversation

@michaelbe812

Copy link
Copy Markdown
Owner

Summary

  • Consolidated duplicate initial value derivation logic into a single utility function
  • Eliminated code duplication while maintaining exact same behavior

Problem

The codebase had two separate implementations for determining initial values during refresh operations:

  1. calcStartValueForRefresh utility function (with tests but unused)
  2. deriveInitialValue inline function in create-state.ts (no direct tests)

This duplication created maintenance burden and risk of inconsistent behavior.

Solution

  • Refactored deriveInitialValue to internally use the existing calcStartValueForRefresh utility
  • Kept both functions to maintain API compatibility
  • deriveInitialValue is now a thin wrapper that creates an RxJS operator using the centralized logic

Changes

  • Added import for calcStartValueForRefresh in create-state.ts
  • Simplified deriveInitialValue to delegate to calcStartValueForRefresh
  • Removed 19 lines of duplicate code

Testing

  • ✅ All existing tests pass
  • ✅ Linting passes
  • ✅ No behavioral changes - the refactored code produces identical results

Benefits

  • Single source of truth for initial value logic
  • Better test coverage (tests already exist for calcStartValueForRefresh)
  • Easier maintenance
  • Clear separation of concerns

Fixes #51

- Replace inline deriveInitialValue implementation with calcStartValueForRefresh utility
- Eliminates code duplication while maintaining same behavior
- Improves maintainability with single source of truth for initial value logic
- Preserves existing API and all tests continue to pass

Fixes #51
@michaelbe812
michaelbe812 force-pushed the fix/consolidate-initial-value-logic branch from 10fabb2 to a4f2ae0 Compare September 16, 2025 13:13
@michaelbe812
michaelbe812 merged commit b6aea49 into main Sep 16, 2025
1 check passed
@michaelbe812
michaelbe812 deleted the fix/consolidate-initial-value-logic branch September 16, 2025 13:17
@michaelbe812
michaelbe812 restored the fix/consolidate-initial-value-logic branch September 16, 2025 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidate duplicate initial value derivation logic

1 participant