Skip to content

feat(core): simplify SignalContainer & add type-safe computedFrom overloads - #480

Open
rodydavis wants to merge 7 commits into
mainfrom
feat/computed-from-and-container-simplification
Open

feat(core): simplify SignalContainer & add type-safe computedFrom overloads#480
rodydavis wants to merge 7 commits into
mainfrom
feat/computed-from-and-container-simplification

Conversation

@rodydavis

Copy link
Copy Markdown
Owner

Overview

This PR simplifies the generic API signature of SignalContainer across the reactivity framework and introduces 10 strongly-typed global overloads and Record-tuple extensions for the computedFrom API. These additions ensure type-safety, enhance the DX (developer experience), and modernize the API structure.


Detailed Changes

1. Core Simplification & Cleanup (packages/signals_core)

  • Redundant generic removal: Removed the redundant type parameter T from SignalContainer<Arg, S> (and its constructor helper functions), making the container class much cleaner and less prone to generic parameter noise.
  • Imports Cleanup: Removed the unused import '../async/state.dart'; statement from container.dart.

2. Type-Safe computedFrom Overloads & Record Extensions

Introduced strongly-typed overloads and record-tuple extension methods to solve type issues with multi-dependency asynchronous computed signals:

  • Overloaded Global Helpers: Implemented computedFrom1 through computedFrom10 which accept individual, strongly-typed ReadonlySignal dependencies and automatically pass type-safe values to their callbacks (e.g., FutureOr<T> Function(A, B, C)).
  • Record-Tuple Extensions: Implemented ComputedFromExt1 through ComputedFromExt10 which enable elegant, premium inline bindings directly on Dart Records:
    final s1 = signal(1);
    final s2 = signal('a');
    
    final combined = (s1, s2).computedFrom((a, b) async {
      // a is typed as int, b is typed as String
      return '$a-$b';
    });

3. Package Version Bumps

Updated all pubspec.yaml and CHANGELOG.md files to trigger minor version increases for the affected packages:

  • signals_core: 7.0.07.1.0
  • signals: 7.1.07.2.0
  • signals_flutter: 7.1.07.2.0
  • signals_hooks: 7.1.07.2.0
  • signals_lint: 7.0.07.1.0

4. Tests & Documentation

  • Comprehensive Tests: Added comprehensive test cases in a new file packages/signals_core/test/async/computed_from_test.dart to verify all 10 overload levels, record-tuple extensions, reactive recalculation behavior, and value type-safety.
  • Auto-generated Documentation: Regenerated all reference docs and Jaspr documentation configurations using dart scripts/generate_docs.dart.

Verification & Testing Results

1. Unit Tests

All 829 test cases in the test suite passed successfully:

dart test
  • Status: All tests passed!

2. Static Analysis

Ran a workspace analysis across the modified packages:

dart analyze
  • Status: No issues found!

@rodydavis rodydavis added the enhancement New feature or request label May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SignalContainer has a useless T generic Add computedFrom convenience functions

1 participant