Typed Resource States
This document describes the plan for adding typed ResourceState support to DRFT.
Goal
Make resources type-safe by having each Resource specify its own ResourceState type:
class ProvisioningProfileState extends ResourceState {
String get bundleId => getRequiredProperty<String>('bundleId');
String get type => getRequiredProperty<String>('type');
List<String> get certificates =>
(getProperty<List<dynamic>>('certificates') ?? [])
.map((e) => e as String)
.toList();
}
class ProvisioningProfile extends Resource<ProvisioningProfileState> {
final String bundleId;
final String type;
final List<String> certificates;
const ProvisioningProfile({
required super.id,
required this.bundleId,
required this.type,
this.certificates = const [],
});
}
Benefits
- Type Safety: Compile-time checking of property access
- IDE Support: Autocomplete for state properties
- Documentation: State properties are clearly defined
- Refactoring: Easier to refactor property names
Phase 1: Base Classes
- Make ResourceState a concrete class with helper methods
- Add
getProperty<T>()andgetRequiredProperty<T>()methods - Make Resource generic:
Resource<StateType extends ResourceState> - Update Provider interface to work with generic resources