refactor: app metadata#28113
Conversation
6a0b40e to
ab28daa
Compare
fd98daa to
4fc0e42
Compare
4fc0e42 to
620ca2d
Compare
| final MetadataDomain domain; | ||
| final String name; | ||
| final T defaultValue; | ||
| final List<T>? enumValues; |
There was a problem hiding this comment.
The values on the enum classes cannot be accessed dynamically so we need a way to store the list of possible values for each enum metadata so we can deserialise it from the reoo
| final enumValues = key.enumValues; | ||
| if (enumValues != null) { | ||
| return enumValues.where((v) => (v as Enum).name == raw).firstOrNull ?? key.defaultValue; | ||
| } | ||
| return switch (key.defaultValue) { | ||
| DateTime() => (DateTime.tryParse(raw) ?? key.defaultValue) as T, | ||
| _ => throw ArgumentError('Unsupported metadata value type: ${key.defaultValue.runtimeType}'), | ||
| }; |
There was a problem hiding this comment.
Likewise, I think the enum and type handling here is a bit weird. I wonder if there's a nicer way to do this.
There was a problem hiding this comment.
The alternative is to drop the generic handling and let every enum key provide it's own encoder and decoder. We could also have a list of predefined codecs for the primitives. I initially had it that way but then each Metadata key definition got lengthier, so resorted to this generic implementation. Moving to a per-key codec would also let us drop the enumValues on the key as it is used during the decoding logic to get the enum value from the string
| Stream<AppConfig> watchAppConfig() => _watchDomain(MetadataDomain.appConfig).map((_) => appConfig).distinct(); | ||
|
|
||
| Stream<SystemConfig> watchSystemConfig() => | ||
| _watchDomain(MetadataDomain.systemConfig).map((_) => systemConfig).distinct(); |
There was a problem hiding this comment.
I think it's weird to use map like this
73daf26 to
e12f311
Compare
e12f311 to
c05cdc1
Compare
Description