Skip to content

Optional nullable #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a typedef for the nested callback
  • Loading branch information
kevmoo committed Jul 24, 2017
commit e4be76b9173dc86f8cf156734e23eda18fae29e3
6 changes: 4 additions & 2 deletions lib/src/type_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ List<DartType> typeArgumentsOf(DartType type, TypeChecker checker) {
return implementation?.typeArguments;
}

typedef String TypeHelperGenerator(DartType t, String e);

abstract class TypeHelper {
const TypeHelper();

Expand All @@ -35,7 +37,7 @@ abstract class TypeHelper {
/// ```.
// TODO(kevmoo) – document `serializeNested`
String serialize(DartType targetType, String expression,
String serializeNested(DartType t, String e));
TypeHelperGenerator serializeNested);

/// Returns Dart code that deserializes an [expression] representing a JSON
/// literal to into [targetType].
Expand All @@ -62,7 +64,7 @@ abstract class TypeHelper {
/// ```.
// TODO(kevmoo) – document `deserializeNested`
String deserialize(DartType targetType, String expression,
String deserializeNested(DartType t, String e));
TypeHelperGenerator deserializeNested);
}

/// A [TypeChecker] for [String], [bool] and [num].
Expand Down
4 changes: 2 additions & 2 deletions lib/src/type_helpers/iterable_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class IterableHelper extends TypeHelper {

@override
String serialize(DartType targetType, String expression,
String serializeNested(DartType dartType, String expression)) {
TypeHelperGenerator serializeNested) {
if (!_coreIterableChecker.isAssignableFromType(targetType)) {
return null;
}
Expand Down Expand Up @@ -44,7 +44,7 @@ class IterableHelper extends TypeHelper {

@override
String deserialize(DartType targetType, String expression,
String deserializeNested(DartType t, String e)) {
TypeHelperGenerator deserializeNested) {
if (!_coreIterableChecker.isAssignableFromType(targetType)) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/type_helpers/map_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MapHelper extends TypeHelper {

@override
String serialize(DartType targetType, String expression,
String serializeNested(DartType t, String e)) {
TypeHelperGenerator serializeNested) {
if (!_coreMapChecker.isAssignableFromType(targetType)) {
return null;
}
Expand Down Expand Up @@ -47,7 +47,7 @@ class MapHelper extends TypeHelper {

@override
String deserialize(DartType targetType, String expression,
String deserializeNested(DartType t, String e)) {
TypeHelperGenerator deserializeNested) {
if (!_coreMapChecker.isAssignableFromType(targetType)) {
return null;
}
Expand Down
6 changes: 2 additions & 4 deletions lib/src/type_helpers/value_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ class ValueHelper extends TypeHelper {
const ValueHelper();

@override
String serialize(DartType targetType, String expression,
String Function(DartType, String) serializeNested) {
String serialize(DartType targetType, String expression, _) {
if (targetType.isDynamic ||
targetType.isObject ||
simpleJsonTypeChecker.isAssignableFromType(targetType)) {
Expand All @@ -17,8 +16,7 @@ class ValueHelper extends TypeHelper {
}

@override
String deserialize(DartType targetType, String expression,
String Function(DartType, String) deserializeNested) {
String deserialize(DartType targetType, String expression, _) {
if (targetType.isDynamic || targetType.isObject) {
// just return it as-is. We'll hope it's safe.
return expression;
Expand Down