Skip to content

Conversation

@leoafarias
Copy link
Collaborator

Improved self-discovery system with the use of the gen_helpers package in preparation for 2.0 changes.

leoafarias added 26 commits June 5, 2025 14:23
…lity

## Summary
Introduces a unified Token<T> class to consolidate duplicate token implementations
while maintaining full compatibility with existing token system and new main branch changes.

## Key Features
- **Generic Token<T> class**: Replaces ColorToken, SpaceToken, TextStyleToken, RadiusToken
- **Type safety**: Compile-time type checking with Token<Color>, Token<double>, etc.
- **Zero breaking changes**: Full backwards compatibility during migration
- **Eliminates negative hashcode hack**: Clean SpaceToken reference handling
- **DTO integration**: ColorDto.token(), TextStyleDto.token(), SpaceDto.token()
- **Utility extensions**: .token() methods alongside existing .ref() methods

## Compatibility with Recent Main Branch Changes
- ✅ **ComputedStyle system**: Token resolution happens before style computation
- ✅ **AnimatedSpecWidget**: Tokens work seamlessly with new animation system
- ✅ **Spec consolidation**: Token resolution abstracted at DTO level
- ✅ **MixData improvements**: Follows new patterns and deprecation guidelines

## Migration Path
```dart
// Old way (still works with deprecation warnings)
$box.color.ref(ColorToken('primary'))
$box.padding.ref(SpaceToken('large'))

// New way
$box.color.token(Token<Color>('primary'))
$box.padding.token(Token<double>('large'))
```

## Technical Details
- Tokens resolve through existing MixTokenResolver for compatibility
- Generic type system provides compile-time safety
- Comprehensive test coverage with integration tests
- Migration guides and deprecation notices included
…hitecture

This commit introduces a major simplification of the token system by implementing
a unified resolver architecture that eliminates duplicate token storage patterns
and reduces system complexity from 5 layers to 3 layers.

## Key Changes

### Core Infrastructure
- Add ValueResolver interface with StaticResolver and LegacyResolver implementations
- Introduce unified token storage (Map<String, ValueResolver<dynamic>>) in MixThemeData
- Simplify Token<T> class to pure data container with direct resolution capability
- Update MixTokenResolver to support unified token resolution with fallback capability

### DTO System Updates
- Update ColorDto to use unified resolver system, eliminating ColorRef dependency
- Create RadiusDto following same pattern as ColorDto for consistent token handling
- Add token() methods directly to utility classes (ColorUtility, TextStyleUtility)
- Remove extension-based token methods to fix protected member access issues

### Architecture Improvements
- Maintain full backwards compatibility with existing legacy token systems
- Reduce code duplication by consolidating resolution logic into single path
- Simplify Token<T> interface by removing call() method and complex delegation
- Enable direct token usage: Token<Color>('primary').resolve(context)

### Testing & Quality
- Update all token tests to work with simplified Token<T> interface
- Fix const evaluation errors in shape border tests
- Clean unused imports and resolve all analysis issues
- Add comprehensive test coverage for unified resolver system

### Generated Code
- Regenerate all generated files to fix InvalidType issues in modifiers
- Update build process to properly handle new token architecture
- Ensure all generated utilities work with simplified token system

## Benefits
- 33% reduction in token system complexity (5→3 layers)
- Unified resolution path eliminates duplicate logic
- Simplified Token<T> API is easier to understand and use
- Better type safety with generic Token<T> approach
- Full backwards compatibility ensures smooth migration path

This refactor maintains API compatibility while providing a foundation for
eliminating refs (ColorRef, RadiusRef, TextStyleRef) in favor of direct
token usage throughout the system.
Updates TextStyleDto to use the direct unified resolver system, eliminating
the need for legacy TextStyleToken wrapper objects and providing consistent
token resolution across all DTO types.

## Changes

### Core Implementation
- Replace legacy TextStyleToken wrapper with direct unified resolver call
- Update resolve() method to use `mix.tokens.resolveToken<TextStyle>(token\!.name)`
- Simplify token resolution path by removing intermediate object creation
- Update documentation to reflect streamlined resolution process

### Testing
- Add comprehensive test for unified token resolution using MixThemeData.unified
- Verify token resolution works correctly with TextStyleDto.token() factory
- Ensure all existing tests continue to pass with new implementation
- Test covers font size, weight, and color resolution from tokens

### Benefits
- Consistent API with ColorDto and RadiusDto unified resolver usage
- Improved performance by eliminating TextStyleToken wrapper allocation
- Simplified code path reduces complexity and potential error points
- Maintains full backwards compatibility with existing TextStyleDataRef system

### Compatibility
- All existing tests pass without modification
- Legacy TextStyleDataRef continues to work through value list processing
- TextStyleDto.ref() factory remains functional for gradual migration
- No breaking changes to public API surface

This completes Phase 2C of the unified resolver migration, bringing TextStyleDto
in line with the simplified token architecture established for other DTO types.
Completes DTO migration by updating SpaceDto to use direct unified resolver,
maintaining consistency with ColorDto, TextStyleDto, and RadiusDto patterns.

## Changes

### Core Implementation
- Replace SpaceToken wrapper with direct unified resolver call
- Update resolve() method to use `mix.tokens.resolveToken<double>(token\!.name)`
- Remove unused SpaceToken import to clean up dependencies
- Maintain backwards compatibility for value-based SpaceDto usage

### Testing Updates
- Update integration test to use MixThemeData.unified instead of legacy SpaceToken mappings
- Create comprehensive SpaceDto unit test file with token resolution testing
- Verify all existing flex/spacing functionality continues to work
- Add test coverage for unified token resolution with double values

### Integration
- All flex spec tests continue to pass with updated SpaceDto
- Token integration test validates end-to-end unified resolver usage
- Consistent API pattern across all DTO types (Color, TextStyle, Space, Radius)

### Benefits
- Completes unified resolver migration for all major DTO types
- Eliminates final legacy token wrapper (SpaceToken) from resolution path
- Provides consistent developer experience across all token-based DTOs
- Simplifies maintenance with single resolution pattern

This completes Phase 2D of the unified resolver migration, bringing all DTO
types under the simplified token architecture established in previous phases.
- Replace all Token<T> references with MixToken<T> for consistency with unified token system
- Update imports from token.dart to mix_token.dart
- Remove deprecated token.dart file from exports
- Update test files to use MixToken and unified resolver system
- Maintain backwards compatibility with deprecated token types
- Remove @deprecated annotations from ColorToken, TextStyleToken, RadiusToken, and SpaceToken
- Keep these token classes available for backwards compatibility
- Allows clean migration path while maintaining existing API
- Introduced a unified token system alongside legacy APIs in MixThemeData.
- Added optional `Map<MixToken, ValueResolver>? tokens` parameter for new token storage.
- Updated MixThemeData constructors to support both legacy and unified tokens.
- Implemented ValueResolver system for type-safe resolution of tokens.
- Enhanced MixTokenResolver to prioritize unified token storage.
- Updated DTOs and utilities to utilize the new unified token system.
- Modified tests to reflect changes in token usage and ensure compatibility.
- Achieved full backward compatibility with existing StyledTokens structure.
# Conflicts:
#	packages/mix/lib/src/attributes/color/color_dto.dart
#	packages/mix/lib/src/attributes/gap/space_dto.dart
#	packages/mix/lib/src/attributes/text_style/text_style_dto.dart
#	packages/mix/test/src/attributes/color/color_dto_test.dart
- Deleted existing tests for breakpoints, colors, radii, spaces, text styles, and utility functions to streamline the test suite.
- Updated integration tests to utilize new MixableToken structure for color, space, and text style tokens.
- Ensured backward compatibility with old token types while introducing new token types.
- Enhanced token resolution tests to verify functionality with the new MixableToken implementation.
…usability

- Removed the RadiusDto class and replaced it with a simpler Mixable<Radius> typedef.
- Introduced convenience factory functions for creating RadiusDto instances.
- Updated the TextStyleDto to consolidate properties and improve merging logic.
- Added support for composite DTOs in both RadiusDto and TextStyleDto.
- Enhanced the Mixable class to support directives for modifying values.
- Created unit tests for Mixable and DTOs to ensure correct functionality and resolution.
- Removed unnecessary generated code files related to TextStyleDto.
# Conflicts:
#	packages/mix/lib/src/attributes/color/color_dto.dart
#	packages/mix/lib/src/attributes/spacing/edge_insets_dto.dart
#	packages/mix/lib/src/attributes/text_style/text_style_dto.dart
#	packages/mix/lib/src/core/spec.dart
…ad radius; update edge insets, strut style, and various widget modifiers to utilize SpaceDto for dimensions; enhance type discovery and validation tools for improved type registry management.
@docs-page
Copy link

docs-page bot commented Jul 6, 2025

To view this pull requests documentation preview, visit the following URL:

docs.page/btwld/mix~708

Documentation is deployed and generated using docs.page.

@leoafarias leoafarias changed the title Feature/type registry autodiscovery chore: type registry autodiscovery Jul 6, 2025
@leoafarias leoafarias changed the base branch from next to main July 6, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants