Skip to content

Commit fcf56db

Browse files
committed
fix: enhance describe method to support TypeTree for converter retrieval, reformat
1 parent 9a48ad4 commit fcf56db

File tree

3 files changed

+109
-27
lines changed

3 files changed

+109
-27
lines changed

packages/dogs_core/lib/src/schema/spec.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,23 @@ import "package:meta/meta.dart";
2626
/// Extension methods for schema generation on [DogEngine].
2727
extension SchemaGenerateExtension on DogEngine {
2828
/// Generates a schema for the given type [T].
29-
SchemaType describe<T>({SchemaConfig config = const SchemaConfig()}) {
30-
if (SchemaPass.current != null) {
31-
final converter = findAssociatedConverter(T);
32-
if (converter == null) {
33-
throw DogException("No converter found for type $T");
34-
}
35-
return converter.describeOutput(this, config);
29+
SchemaType describe<T>({TypeTree? tree, SchemaConfig config = const SchemaConfig()}) {
30+
final DogConverter? converter;
31+
if (tree == null) {
32+
converter = findAssociatedConverter(T);
33+
} else {
34+
converter = getTreeConverter(tree);
3635
}
3736

38-
final converter = findAssociatedConverter(T);
3937
if (converter == null) {
4038
throw DogException("No converter found for type $T");
4139
}
42-
return SchemaPass.run((pass) {
40+
41+
if (SchemaPass.current != null) {
4342
return converter.describeOutput(this, config);
44-
});
43+
}
44+
45+
return SchemaPass.run((pass) => converter!.describeOutput(this, config));
4546
}
4647

4748
/// Materializes a [type] schema, creating a [MaterializedConverter] that

packages/dogs_flutter/lib/databinding/style.conv.g.dart

Lines changed: 88 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dogs_flutter/test/dogs_flutter_test.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ void main() {
3030
expect(decoded, rect);
3131
dogs.describe<Rect>();
3232

33-
final authored = [0,10,20,25.5];
33+
final authored = [0, 10, 20, 25.5];
3434
final decodedAuthored = dogs.fromNative<Rect>(authored);
35-
expect(decodedAuthored, Rect.fromLTRB(0,10,20,25.5));
35+
expect(decodedAuthored, Rect.fromLTRB(0, 10, 20, 25.5));
3636
});
3737

3838
test("Serialize EdgeInsets", () {
@@ -42,9 +42,9 @@ void main() {
4242
expect(decoded, edgeInsets);
4343
dogs.describe<EdgeInsets>();
4444

45-
final authored = [10,20,30,40.5];
45+
final authored = [10, 20, 30, 40.5];
4646
final decodedAuthored = dogs.fromNative<EdgeInsets>(authored);
47-
expect(decodedAuthored, EdgeInsets.fromLTRB(10,20,30,40.5));
47+
expect(decodedAuthored, EdgeInsets.fromLTRB(10, 20, 30, 40.5));
4848
});
4949

5050
test("Serialize RRect", () {
@@ -72,7 +72,12 @@ void main() {
7272
});
7373

7474
test("Serialize BoxConstraints", () {
75-
final constraints = BoxConstraints(minWidth: 10, maxWidth: 100, minHeight: 20, maxHeight: 200);
75+
final constraints = BoxConstraints(
76+
minWidth: 10,
77+
maxWidth: 100,
78+
minHeight: 20,
79+
maxHeight: 200,
80+
);
7681
final encoded = dogs.toJson<BoxConstraints>(constraints);
7782
final decoded = dogs.fromJson<BoxConstraints>(encoded);
7883
expect(decoded, constraints);

0 commit comments

Comments
 (0)